+*~
*.o
*.lo
*.a
*.la
+*.su
*.log
*.trs
*.tar.xz
}
struct _auth_obj authfile(const char *userid, const char *password,
- void (*update_nonce)(char *nonce, const int nonsize),
- const unsigned char *secret, const int secsize,
- const unsigned char *payload, const int paylsize,
+ void (*update_nonce)(char *nonce, const size_t nonsize),
+ const unsigned char *secret, const size_t secsize,
+ const unsigned char *payload, const size_t paylsize,
struct _auth_chunk (*fetch_key)(const unsigned char *chal,
- const int csize))
+ const size_t csize))
{
struct _auth_obj ret = {0};
const struct passwd *pw = NULL;
ret.err = strerror(errno);
}
if (st.st_uid || st.st_gid) {
- if (fchown(fileno(fp), st.st_uid, st.st_gid)) /*ign*/;
+ if (fchown(fileno(fp), st.st_uid, st.st_gid)) {/*ign*/;}
}
if (fclose(fp) < 0) {
ret.err = strerror(errno);
void authfile_template(const char *template);
struct _auth_obj authfile(const char *userid, const char *password,
- void (*update_nonce)(char *nonce, const int nonsize),
- const unsigned char *secret, const int secsize,
- const unsigned char *payload, const int paysize,
+ void (*update_nonce)(char *nonce, const size_t nonsize),
+ const unsigned char *secret, const size_t secsize,
+ const unsigned char *payload, const size_t paysize,
struct _auth_chunk (*fetch_key)(const unsigned char *chal,
- const int csize));
+ const size_t csize));
#endif
struct _auth_chunk ho = {0};
unsigned long rc;
serializer_t srl;
- int datasize = strlen(uid) + strlen(pass) + strlen(nonce) +
+ size_t datasize = strlen(uid) + strlen(pass) + strlen(nonce) +
4 * sizeof(short);
unsigned char *data = alloca(datasize);
- int hashsize = sizeof(ho.data);
+ size_t hashsize = sizeof(ho.data);
serial_init(&srl, data, datasize);
if (serial_put(&srl, uid, strlen(uid)) != strlen(uid)) {
}
static struct _auth_chunk
-new_key(const unsigned char *challenge, const int challengesize,
- const unsigned char *secret, const int secsize)
+new_key(const unsigned char *challenge, const size_t challengesize,
+ const unsigned char *secret, const size_t secsize)
{
struct _auth_chunk ho = {0};
unsigned long rc;
- int keysize = sizeof(ho.data);
+ size_t keysize = sizeof(ho.data);
if ((rc = hmac(secret, secsize, challenge, challengesize,
&ho.data, &keysize))) {
make_key(const char *userid, const char *password, const char *nonce,
const unsigned char *secret, const int secsize,
struct _auth_chunk (*fetch_key)(const unsigned char *chal,
- const int csize))
+ const size_t csize))
{
struct _auth_chunk ho_chal, ho_key = {0};
static struct _auth_obj
make_authobj(const char *userid, const char *password, const char *nonce,
- const unsigned char *secret, const int secsize,
- const unsigned char *payload, const int paylsize)
+ const unsigned char *secret, const size_t secsize,
+ const unsigned char *payload, const size_t paylsize)
{
struct _auth_obj ao = {0};
unsigned long rc;
unsigned char *data;
- int datasize;
+ size_t datasize;
unsigned char datahash[HASHSIZE];
- int datahashsize = HASHSIZE;
+ size_t datahashsize = HASHSIZE;
serializer_t srl;
datasize = ((secsize + paylsize + HASHSIZE + 4 * sizeof(short) - 1) /
const unsigned char *secret, const int secsize,
const unsigned char *ablob, const int blobsize,
struct _auth_chunk (*fetch_key)(const unsigned char *chal,
- const int csize))
+ const size_t csize))
{
unsigned long rc;
struct _auth_obj ao = {0};
} else {
serializer_t srl;
unsigned char myhash[HASHSIZE];
- int myhsize = HASHSIZE;
+ size_t myhsize = HASHSIZE;
unsigned char *theirhash;
- int theirhsize;
+ size_t theirhsize;
unsigned long rc;
serial_init(&srl, ao.buffer, blobsize);
struct _auth_obj authobj(const char *userid, const char *password,
const char *oldnonce, const char *newnonce,
- const unsigned char *secret, const int secsize,
- const unsigned char *payload, const int paylsize,
- const unsigned char *ablob, const int blobsize,
+ const unsigned char *secret, const size_t secsize,
+ const unsigned char *payload, const size_t paylsize,
+ const unsigned char *ablob, const size_t blobsize,
struct _auth_chunk (*fetch_key)(const unsigned char *chal,
- const int csize))
+ const size_t csize))
{
const unsigned char *wsecret;
int wsecsize;
unsigned char *buffer; /* to be free()'d if not NULL */
const char *err; /* non-NULL if failed */
unsigned char *data;
- int datasize;
+ size_t datasize;
unsigned char *payload;
- int paylsize;
+ size_t paylsize;
};
/* Construct new or repack old authobj, return payload */
struct _auth_obj authobj(const char *userid, const char *password,
const char *oldnonce, const char *newnonce,
- const unsigned char *secret, const int secsize,
- const unsigned char *payload, const int paysize,
- const unsigned char *ablob, const int blobsize,
+ const unsigned char *secret, const size_t secsize,
+ const unsigned char *payload, const size_t paysize,
+ const unsigned char *ablob, const size_t blobsize,
struct _auth_chunk (*fetch_key)(const unsigned char *chal,
- const int csize));
+ const size_t csize));
#endif
result = (fragment & 0x0fc) >> 2;
*codechar++ = base64_encode_value(result);
result = (fragment & 0x003) << 4;
+ /* fallthrough */
case step_B:
if (plainchar == plaintextend)
{
result |= (fragment & 0x0f0) >> 4;
*codechar++ = base64_encode_value(result);
result = (fragment & 0x00f) << 2;
+ /* fallthrough */
case step_C:
if (plainchar == plaintextend)
{
case step_A:
break;
}
- *codechar++ = '\n';
return codechar - code_out;
}
fragment = (char)base64_decode_value(*codechar++);
} while (fragment < 0);
*plainchar = (fragment & 0x03f) << 2;
+ /* fallthrough */
case step_b:
do {
if (codechar == code_in+length_in)
} while (fragment < 0);
*plainchar++ |= (fragment & 0x030) >> 4;
*plainchar = (fragment & 0x00f) << 4;
+ /* fallthrough */
case step_c:
do {
if (codechar == code_in+length_in)
} while (fragment < 0);
*plainchar++ |= (fragment & 0x03c) >> 2;
*plainchar = (fragment & 0x003) << 6;
+ /* fallthrough */
case step_d:
do {
if (codechar == code_in+length_in)
dnl Process this file with autoconf to produce a configure script.
-AC_INIT([pam_pcsc_cr], 0.9.5)
+AC_INIT([pam_pcsc_cr],[0.9.6])
AC_CONFIG_SRCDIR([pam_pcsc_cr.c])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE
-AM_CONFIG_HEADER([config.h])
-AC_LANG_C
+AC_CONFIG_HEADERS([config.h])
+AC_LANG([C])
AC_PROG_CC
if test "X$CC" = "Xgcc"; then
- CFLAGS="$CFLAGS -Wall"
-fi
+ CFLAGS="$CFLAGS -Wextra -Wall -Werror -Wno-unused-parameter -Wno-deprecated-declarations -fstack-protector-all $ASAN_FLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"
+else if test "X$CC" = "Xclang"; then
+ CFLAGS="$CFLAGS -Wextra -Wall -Werror -Wno-unused-parameter -Wno-deprecated-declarations -Wformat -Wformat-security -fstack-protector-all $ASAN_FLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
+fi; fi
AC_PROG_MAKE_SET
AC_SUBST(PROGS)dnl
AC_SUBST(LIBPROGS)dnl
AC_PROG_INSTALL
-AM_PROG_LIBTOOL
+LT_INIT
PKG_PROG_PKG_CONFIG
AC_CHECK_HEADERS([security/pam_appl.h], [], [
is present])
AS_IF([test "x$use_openssl" != "xyes" && test "x$use_tomcrypt" != "xyes" || \
- test "x$enable_tomcrypt" = "xyes"], [
- AM_PATH_LIBGCRYPT()
+ test "x$enable_gcrypt" = "xyes"], [
+ m4_ifdef([AM_PATH_LIBGCRYPT], [
+ AM_PATH_LIBGCRYPT()
+ ], [
+ m4_exit(1)
+ ])
])
AS_IF([test "x$LIBGCRYPT_CFLAGS" != "x" -o "x$LIBGCRYPT_LIBS" != "x" ], [
use_gcrypt=yes
AC_SUBST(CRYPTO_OBJS)
dnl Checks for header files.
-AC_HEADER_STDC
-AC_HEADER_TIME
AC_CHECK_HEADERS([winscard.h reader.h], [],
[AC_MSG_ERROR([[pcsclite headers not found]])])
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
+#include <stddef.h>
#include <assert.h>
#include "crypto.h"
#include "crypto_if.h"
#endif
(struct crypto_interface *)0,
};
-#define MAX_IF (sizeof(ifs)/sizeof(struct crypto_interface *)-2)
+#define MAX_IF (int)(sizeof(ifs)/sizeof(struct crypto_interface *)-2)
static int which = 0;
#define INITIV {0}
-unsigned long encrypt(const void *key, const int keylen, const void *pt, void *ct, const int tlen)
+unsigned long encrypt(const void *key, const size_t keylen, const void *pt, void *ct, const size_t tlen)
{
unsigned char iv[16] = INITIV;
return ifs[which]->encrypt(key, keylen, iv, pt, ct, tlen);
}
-unsigned long decrypt(const void *key, const int keylen, const void *ct, void *pt, const int tlen)
+unsigned long decrypt(const void *key, const size_t keylen, const void *ct, void *pt, const size_t tlen)
{
unsigned char iv[16] = INITIV;
return ifs[which]->decrypt(key, keylen, iv, ct, pt, tlen);
}
-unsigned long hash(const void *pt, const int tlen, void *tag, int *taglen)
+unsigned long hash(const void *pt, const size_t tlen, void *tag, size_t *taglen)
{
assert(*taglen == 20);
return ifs[which]->hash(pt, tlen, tag, taglen);
}
-unsigned long hmac(const void *key, const int keylen, const void *pt, const int tlen, void *tag, int *taglen)
+unsigned long hmac(const void *key, const size_t keylen, const void *pt, const size_t tlen, void *tag, size_t *taglen)
{
assert(*taglen == 20);
return ifs[which]->hmac(key, keylen, pt, tlen, tag, taglen);
int select_crypto_if(const int ifno);
const char *crypto_init(const int ifno);
-unsigned long encrypt(const void *key, const int keylen, const void *pt, void *ct, const int tlen);
-unsigned long decrypt(const void *key, const int keylen, const void *ct, void *pt, const int tlen);
-unsigned long hash(const void *pt, const int tlen, void *tag, int *taglen);
-unsigned long hmac(const void *key, const int keylen, const void *pt, const int tlen,
- void *tag, int *taglen);
+unsigned long encrypt(const void *key, const size_t keylen, const void *pt, void *ct, const size_t tlen);
+unsigned long decrypt(const void *key, const size_t keylen, const void *ct, void *pt, const size_t tlen);
+unsigned long hash(const void *pt, const size_t tlen, void *tag, size_t *taglen);
+unsigned long hmac(const void *key, const size_t keylen, const void *pt, const size_t tlen,
+ void *tag, size_t *taglen);
const char *crypto_errstr(const unsigned long err);
#define HASHSIZE 20
struct crypto_interface {
const char *(*init)(void);
- unsigned long (*encrypt)(const void *key, const int keylen, void *iv,
- const void *pt, void *ct, const int tlen);
- unsigned long (*decrypt)(const void *key, const int keylen, void *iv,
- const void *ct, void *pt, const int tlen);
- unsigned long (*hash)(const void *pt, const int tlen,
- void *tag, int *taglen);
- unsigned long (*hmac)(const void *key, const int keylen,
- const void *pt, const int tlen,
- void *tag, int *taglen);
+ unsigned long (*encrypt)(const void *key, const size_t keylen, void *iv,
+ const void *pt, void *ct, const size_t tlen);
+ unsigned long (*decrypt)(const void *key, const size_t keylen, void *iv,
+ const void *ct, void *pt, const size_t tlen);
+ unsigned long (*hash)(const void *pt, const size_t tlen,
+ void *tag, size_t *taglen);
+ unsigned long (*hmac)(const void *key, const size_t keylen,
+ const void *pt, const size_t tlen,
+ void *tag, size_t *taglen);
const char *(*errstr)(const unsigned long err);
};
return "gcrypt";
}
-static unsigned long gnu_encrypt(const void *key, const int keylen, void *iv,
- const void *pt, void *ct, const int tlen)
+static unsigned long gnu_encrypt(const void *key, const size_t keylen, void *iv,
+ const void *pt, void *ct, const size_t tlen)
{
gcry_error_t err;
gcry_cipher_hd_t hd;
return 0UL;
}
-static unsigned long gnu_decrypt(const void *key, const int keylen, void *iv,
- const void *ct, void *pt, const int tlen)
+static unsigned long gnu_decrypt(const void *key, const size_t keylen, void *iv,
+ const void *ct, void *pt, const size_t tlen)
{
gcry_error_t err;
gcry_cipher_hd_t hd;
return 0UL;
}
-static unsigned long gnu_hash(const void *pt, const int tlen,
- void *tag, int *taglen)
+static unsigned long gnu_hash(const void *pt, const size_t tlen,
+ void *tag, size_t *taglen)
{
gcry_error_t err;
gcry_md_hd_t hd;
return 0UL;
}
-static unsigned long gnu_hmac(const void *key, const int keylen,
- const void *pt, const int tlen,
- void *tag, int *taglen)
+static unsigned long gnu_hmac(const void *key, const size_t keylen,
+ const void *pt, const size_t tlen,
+ void *tag, size_t *taglen)
{
gcry_error_t err;
gcry_md_hd_t hd;
return "openssl";
}
-static unsigned long ossl_encrypt(const void *key, const int keylen, void *iv,
- const void *pt, void *ct, const int tlen)
+static unsigned long ossl_encrypt(const void *key, const size_t keylen, void *iv,
+ const void *pt, void *ct, const size_t tlen)
{
AES_KEY akey;
return 0UL;
}
-static unsigned long ossl_decrypt(const void *key, const int keylen, void *iv,
- const void *ct, void *pt, const int tlen)
+static unsigned long ossl_decrypt(const void *key, const size_t keylen, void *iv,
+ const void *ct, void *pt, const size_t tlen)
{
AES_KEY akey;
return 0UL;
}
-static unsigned long ossl_hash(const void *pt, const int tlen,
- void *tag, int *taglen)
+static unsigned long ossl_hash(const void *pt, const size_t tlen,
+ void *tag, size_t *taglen)
{
SHA_CTX sctx;
return 0UL;
}
-static unsigned long ossl_hmac(const void *key, int const keylen,
- const void *pt, const int tlen,
- void *tag, int *taglen)
+static unsigned long ossl_hmac(const void *key, size_t const keylen,
+ const void *pt, const size_t tlen,
+ void *tag, size_t *taglen)
{
#if 0
HMAC_CTX hctx;
#include "pcsc_cr.h"
static struct _auth_chunk
-token_key(const unsigned char *challenge, const int challengesize)
+token_key(const unsigned char *challenge, const size_t challengesize)
{
struct _auth_chunk ho = {0};
long rc;
- int keysize = sizeof(ho.data);
+ size_t keysize = sizeof(ho.data);
if ((rc = pcsc_cr(challenge, challengesize, ho.data, &keysize))) {
ho.err = pcsc_errstr(rc);
static char *mynonce = NULL;
-static void update_nonce(char *nonce, const int nonsize)
+static void update_nonce(char *nonce, const size_t nonsize)
{
if (mynonce) {
snprintf(nonce, nonsize, "%s", mynonce);
exit(EXIT_FAILURE);
} else if (verbose) {
printf("version: %s\n", VERSION);
- printf("userid : \"%.*s\"\n", ao.datasize, ao.data);
- printf("payload: \"%.*s\"\n", ao.paylsize, ao.payload);
+ printf("userid : \"%.*s\"\n", (int)ao.datasize, ao.data);
+ printf("payload: \"%.*s\"\n", (int)ao.paylsize, ao.payload);
}
if (ao.buffer) free(ao.buffer);
return 0;
#endif
static struct _auth_chunk
-token_key(const unsigned char *challenge, const int challengesize)
+token_key(const unsigned char *challenge, const size_t challengesize)
{
struct _auth_chunk ho = {0};
long rc;
- int keysize = sizeof(ho.data);
+ size_t keysize = sizeof(ho.data);
if ((rc = pcsc_cr(challenge, challengesize, ho.data, &keysize))) {
ho.err = pcsc_errstr(rc);
return ho;
}
-static void update_nonce(char *nonce, const int nonsize)
+static void update_nonce(char *nonce, const size_t nonsize)
{
int n = 0;
}
ao = authfile(user, password, update_nonce,
- NULL, 0, NULL, 0, token_key);
+ NULL, (size_t)0, NULL, (size_t)0, token_key);
if (ao.err) {
if (cfg.verbose) syslog(LOG_INFO, "authfile: %s", ao.err);
return PAM_AUTH_ERR;
static LONG find_hb(BYTE *atr, DWORD atrsize, BYTE **hb, LPDWORD hbsize)
{
- int i, j, cont;
+ DWORD i;
+ int j, cont;
if (atrsize < 2) return SCARD_W_UNSUPPORTED_CARD;
switch (atr[0]) {
case 0x3B: break;
#define _PCSC_CR_H
int pcsc_option(const char *option);
-long pcsc_cr(const unsigned char *chal, const int csize,
- unsigned char *resp, int *rsize);
+long pcsc_cr(const unsigned char *chal, const size_t csize,
+ unsigned char *resp, size_t *rsize);
char *pcsc_errstr(long err);
#endif
--- /dev/null
+#ifndef _READER_H
+#define _READER_H
+
+struct reader_ctx;
+struct target_ctx;
+
+struct reader_interface {
+ char *name;
+ struct reader_ctx *(*init_ctx) (void);
+ int (*parse_option)(struct reader_ctx * ctx, char *key, char *val);
+ int (*for_each_target)(struct reader_ctx * ctx,
+ (int *callback)(struct target_ctx * tgt,
+ void *arg), void *arg);
+ void (*drop_ctx)(*struct reader_ctx * ctx);
+ int (*transcieve)(struct target_ctx * tgt, uint8_t * send,
+ size_t send_size, uint8_t * recv,
+ size_t *recv_size_p);
+};
+
+#endif
#include <string.h>
#include "serial.h"
-void serial_init(serializer_t *srl, void *buffer, int size)
+void serial_init(serializer_t *srl, void *buffer, size_t size)
{
srl->buffer = srl->cursor = buffer;
srl->bufsize = size;
}
-void serial_switch(serializer_t *srl, void *buffer, int size)
+void serial_switch(serializer_t *srl, void *buffer, size_t size)
{
- int used = srl->cursor - srl->buffer;
+ size_t used = srl->cursor - srl->buffer;
memcpy(buffer, srl->buffer, used);
srl->buffer = buffer;
}
/* returns 'size' on success, or remainging space if it was insufficient */
-int serial_put(serializer_t *srl, const void *item, int size)
+size_t serial_put(serializer_t *srl, const void *item, size_t size)
{
- int left = srl->bufsize - (srl->cursor - srl->buffer);
+ size_t left = srl->bufsize - (srl->cursor - srl->buffer);
if (left < size + sizeof(short)) return left - sizeof(short);
*((short *)srl->cursor) = size;
}
/* return 0 on success, -1 on wrong encoding (item longer than space left) */
-int serial_get(serializer_t *srl, void **item, int *size)
+int serial_get(serializer_t *srl, void **item, size_t *size)
{
- int left = srl->bufsize - (srl->cursor - srl->buffer);
+ size_t left = srl->bufsize - (srl->cursor - srl->buffer);
short isize = *((short *)srl->cursor);
if (isize + sizeof(short) > left) return -1;
return 0;
}
-int serial_size(serializer_t *srl)
+size_t serial_size(serializer_t *srl)
{
return srl->cursor - srl->buffer;
}
typedef struct _serializer {
char *buffer;
- int bufsize;
+ size_t bufsize;
char *cursor;
} serializer_t;
-void serial_init(serializer_t *srl, void *buffer, int size);
-void serial_switch(serializer_t *srl, void *buffer, int size);
-int serial_put(serializer_t *srl, const void *item, int size);
-int serial_get(serializer_t *srl, void **item, int *size);
-int serial_size(serializer_t *srl);
+void serial_init(serializer_t *srl, void *buffer, size_t size);
+void serial_switch(serializer_t *srl, void *buffer, size_t size);
+size_t serial_put(serializer_t *srl, const void *item, size_t size);
+int serial_get(serializer_t *srl, void **item, size_t *size);
+size_t serial_size(serializer_t *srl);
#endif
};
static struct _auth_chunk
-conjure_key(const unsigned char *challenge, const int challengesize)
+conjure_key(const unsigned char *challenge, const size_t challengesize)
{
struct _auth_chunk ho = {0};
long rc;
- int keysize = sizeof(ho.data);
+ size_t keysize = sizeof(ho.data);
if ((rc = hmac(secret, sizeof(secret), challenge, challengesize,
&ho.data, &keysize))) {
}
static struct _auth_chunk
-token_key(const unsigned char *challenge, const int challengesize)
+token_key(const unsigned char *challenge, const size_t challengesize)
{
struct _auth_chunk ho = {0};
long rc;
- int keysize = sizeof(ho.data);
+ size_t keysize = sizeof(ho.data);
if ((rc = pcsc_cr(challenge, challengesize, ho.data, &keysize))) {
ho.err = pcsc_errstr(rc);
const char *nonce = "1";
const unsigned char *payload = (unsigned char *)
"To authorize or not to authorize?";
- int i;
+ size_t i;
struct _auth_obj ao;
struct _auth_obj nao;
struct _auth_chunk (*fetch_key)(const unsigned char *challenge,
- const int challengesize);
+ const size_t challengesize);
if (argc == 2 && strlen(argv[1]) == 40 &&
strspn(argv[1], "0123456789abcdefABCDEF") == 40) {
payload, strlen((char *)payload),
NULL, 0, NULL);
printf("new_authobj err=%s\n", ao.err?ao.err:"<no error>");
- printf("data(%d):", ao.datasize);
+ printf("data(%d):", (int)ao.datasize);
for (i = 0; i < ao.datasize; i++) printf(" %02x", ao.data[i]);
- printf("\npayload(%d): \"%.*s\"\n", ao.paylsize, ao.paylsize,
+ printf("\npayload(%d): \"%.*s\"\n", (int)ao.paylsize, (int)ao.paylsize,
ao.payload?(char*)ao.payload:"");
if (ao.err) {
if (ao.buffer) free(ao.buffer);
nao = authobj(id, pass, nonce, nonce, NULL, 0, NULL, 0,
ao.data, ao.datasize, fetch_key);
printf("verify_authobj err=%s\n", nao.err?nao.err:"<no error>");
- printf("data(%d):", nao.datasize);
+ printf("data(%d):", (int)nao.datasize);
for (i = 0; i < nao.datasize; i++) printf(" %02x", nao.data[i]);
- printf("\npayload(%d): \"%.*s\"\n", nao.paylsize, nao.paylsize,
+ printf("\npayload(%d): \"%.*s\"\n", (int)nao.paylsize, (int)nao.paylsize,
nao.payload?(char*)nao.payload:"");
if (nao.err) {
if (nao.buffer) free(nao.buffer);
int main(int argc, char *argv[])
{
- char b64[80];
- unsigned char dst[44];
+ int rc;
+ char b64[57]; /* Must be: ((ssize-1)/3+1)*4+1) = 57 */
+ char unsigned dst[42]; /* Must be: strlen(b64)*3/4 = 42 */
int bsize, dsize;
- printf("src=\"%s\" (%d)\n", src, (int)sizeof(src));
+ printf("src=\"%s\" (%lu/%d)\n", src, strlen((char *)src), (int)sizeof(src));
bsize = sizeof(b64);
if (b64_encode(src, sizeof(src), b64, &bsize)) {
fprintf(stderr, "encode error\n");
return 1;
}
- printf("b64=\"%s\" (%d)\n", b64, bsize);
+ printf("b64=\"%s\" (%lu/%d)\n", b64, strlen(b64), bsize);
dsize = sizeof(dst);
- if (b64_decode(b64, dst, &dsize)) {
- fprintf(stderr, "decode error\n");
+ if ((rc = b64_decode(b64, dst, &dsize))) {
+ fprintf(stderr, "decode error, rc=%d\n", rc);
return 1;
}
- printf("dst=\"%s\" (%d)\n", dst, dsize);
+ printf("dst=\"%s\" (%lu/%d)\n", dst, strlen((char *)dst), dsize);
return !(dsize == sizeof(src) && !memcmp(src, dst, dsize));
}
int main(int argc, char *argv[])
{
unsigned char chal[64];
- int csize;
+ size_t csize;
unsigned char rbuf[20];
- int rsize = sizeof(rbuf);
- int i;
+ size_t rsize = sizeof(rbuf);
+ size_t i;
long rc;
int c;
csize = strlen(argv[optind]);
if (csize > sizeof(chal)) {
fprintf(stderr, "Challenge longer than %d, cannot do that\n",
- csize);
+ (int)csize);
exit(1);
}
#if 0
memset(rbuf, 0xFE, sizeof(rbuf));
rc = pcsc_cr(chal, csize, rbuf, &rsize);
- printf("rc=%ld (%s) rsize=%d:", rc, pcsc_errstr(rc), rsize);
+ printf("rc=%ld (%s) rsize=%d:", rc, pcsc_errstr(rc), (int)rsize);
for (i = 0; i < rsize; i++) printf(" %02x", rbuf[i]);
printf("\n");
return rc;
#define printh(x) printh_f(#x, x, sizeof(x))
void printh_f(char *p, unsigned char *x, size_t l)
{
- int i;
+ size_t i;
printf("%s:", p);
for (i=0; i<l; i++) printf(" %02x", x[i]);
printf("\n");
{
unsigned char sha1[20];
unsigned long err;
- int shalen;
+ size_t shalen;
unsigned char spt[3] = "abc";
unsigned char sstd[20] = {0xA9,0x99,0x3E,0x36,0x47,0x06,0x81,0x6A,
0xBA,0x3E,0x25,0x71,0x78,0x50,0xC2,0x6C,0x9C,0xD0,0xD8,0x9D};
printf("hash error: %s\n", crypto_errstr(err));
return 1;
}
- printf("%d: len=%d ", iface, shalen);
+ printf("%d: len=%d ", iface, (int)shalen);
printh(sha1);
if (memcmp(sha1, sstd, sizeof(sstd))) {
printf("fail\n");
{
unsigned char hmac1[20];
unsigned long err;
- int hmaclen;
+ size_t hmaclen;
unsigned char hpt[28] = "what do ya want for nothing?";
unsigned char hkey[4] = "Jefe";
unsigned char hstd[20] = {0xef,0xfc,0xdf,0x6a,0xe5,0xeb,0x2f,0xa2,
printf("hash error: %s\n", crypto_errstr(err));
return 1;
}
- printf("%d: len=%d ", iface, hmaclen);
+ printf("%d: len=%d ", iface, (int)hmaclen);
printh(hmac1);
if (memcmp(hmac1, hstd, sizeof(hstd))) {
printf("fail\n");
printf("serial_put(..., NULL, 0) = %d\n", rc);
return 1;
}
- printf("serialized size=%d\n", serial_size(&srl));
+ printf("serialized size=%d\n", (int)serial_size(&srl));
serial_init(&srl, buffer, sizeof(buffer));
for (i = 0; i < 4; i++) {
char *item;
- int size;
+ size_t size;
if (serial_get(&srl, (void**)&item, &size)) {
printf("serial_get failed for item %d\n", i);
rc = 1;
} else {
- printf("serial_get(...) = %d: \"%.*s\"\n", size, size, item);
+ printf("serial_get(...) = %d: \"%.*s\"\n", (int)size, (int)size, item);
if (memcmp(in[i], item, size)) {
printf("\"%s\" != \"%s\" (%d)\n",
- in[i], item, size);
+ in[i], item, (int)size);
rc = 1;
}
}
return "tomcrypt";
}
-static unsigned long tom_encrypt(const void *key, const int keylen, void *iv,
- const void *pt, void *ct, const int tlen)
+static unsigned long tom_encrypt(const void *key, const size_t keylen, void *iv,
+ const void *pt, void *ct, const size_t tlen)
{
symmetric_CBC cbc;
int index, err;
return err;
}
-static unsigned long tom_decrypt(const void *key, const int keylen, void *iv,
- const void *ct, void *pt, const int tlen)
+static unsigned long tom_decrypt(const void *key, const size_t keylen, void *iv,
+ const void *ct, void *pt, const size_t tlen)
{
symmetric_CBC cbc;
int index, err;
return err;
}
-static unsigned long tom_hash(const void *pt, const int tlen,
- void *tag, int *taglen)
+static unsigned long tom_hash(const void *pt, const size_t tlen,
+ void *tag, size_t *taglen)
{
int index, rc;
unsigned long ltaglen = *taglen;
return rc;
}
-static unsigned long tom_hmac(const void *key, const int keylen,
- const void *pt, const int tlen,
- void *tag, int *taglen)
+static unsigned long tom_hmac(const void *key, const size_t keylen,
+ const void *pt, const size_t tlen,
+ void *tag, size_t *taglen)
{
int index, rc;
unsigned long ltaglen = *taglen;