]> www.average.org Git - pam_pcsc_cr.git/commitdiff
configure.ac: remove sanitizer by default master
authorEugene Crosser <crosser@average.org>
Mon, 5 Jun 2023 19:59:32 +0000 (21:59 +0200)
committerEugene Crosser <crosser@average.org>
Tue, 6 Jun 2023 17:51:14 +0000 (19:51 +0200)
25 files changed:
.gitignore
authfile.c
authfile.h
authobj.c
authobj.h
base64.c
configure.ac
crypto.c
crypto.h
crypto_if.h
gnu_crypto.c
ossl_crypto.c
pam_cr_setup.c
pam_pcsc_cr.c
pcsc_cr.c
pcsc_cr.h
reader.h [new file with mode: 0644]
serial.c
serial.h
test_auth.c
test_base64.c
test_chalresp.c
test_crypto.c
test_serial.c
tom_crypto.c

index 9bad79ded70b9af772fd81cb44e2a4423a46c4b4..6a3d3d2ac907b0830795717881d96fc42e5da6df 100644 (file)
@@ -1,7 +1,9 @@
+*~
 *.o
 *.lo
 *.a
 *.la
+*.su
 *.log
 *.trs
 *.tar.xz
index 93157a4e1a9a8460c46a6fc609e1b18a62fd5885..17354b8cb490adcbda42f05bf851423945d9db2f 100644 (file)
@@ -108,11 +108,11 @@ int parse(char * const buf, const int argc, const char *argv[const])
 }
 
 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;
@@ -200,7 +200,7 @@ struct _auth_obj authfile(const char *userid, const char *password,
                        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);
index ad6fbc1db56243c27156df83184685a5c5e50b74..1a304f64de3fc2f9ce7d588abed2d3b21aa7e97a 100644 (file)
@@ -27,10 +27,10 @@ freely, subject to the following restrictions:
 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
index b4a1f2be26e1f3e3a284a128a5a6ba49c2aac954..7e3c2eddc1ae30b222a14e23896ca529bde9bd16 100644 (file)
--- a/authobj.c
+++ b/authobj.c
@@ -38,10 +38,10 @@ make_challenge(const char *uid, const char *pass, const char *nonce)
        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)) {
@@ -65,12 +65,12 @@ make_challenge(const char *uid, const char *pass, const char *nonce)
 }
 
 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))) {
@@ -85,7 +85,7 @@ static struct _auth_chunk
 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};
 
@@ -112,15 +112,15 @@ make_key(const char *userid, const char *password, const char *nonce,
 
 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) /
@@ -182,7 +182,7 @@ parse_authobj(const char *userid, const char *password, const char *nonce,
                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};
@@ -199,9 +199,9 @@ parse_authobj(const char *userid, const char *password, const char *nonce,
        } 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);
@@ -227,11 +227,11 @@ parse_authobj(const char *userid, const char *password, const char *nonce,
 
 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;
index 158c52c7d3d145e03845b2742d10e9cbce577be6..6814264efbd70f5abb65a8823c7f97d2244c4168 100644 (file)
--- a/authobj.h
+++ b/authobj.h
@@ -35,18 +35,18 @@ struct _auth_obj {
        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
index 8f16cdc0306b0dd1125ab9ca40459f6e779ee95b..96ae3b8bca90897430b46309623dede1616c417b 100644 (file)
--- a/base64.c
+++ b/base64.c
@@ -91,6 +91,7 @@ static int base64_encode_block(const unsigned char* plaintext_in, int length_in,
                        result = (fragment & 0x0fc) >> 2;
                        *codechar++ = base64_encode_value(result);
                        result = (fragment & 0x003) << 4;
+                       /* fallthrough */
        case step_B:
                        if (plainchar == plaintextend)
                        {
@@ -102,6 +103,7 @@ static int base64_encode_block(const unsigned char* plaintext_in, int length_in,
                        result |= (fragment & 0x0f0) >> 4;
                        *codechar++ = base64_encode_value(result);
                        result = (fragment & 0x00f) << 2;
+                       /* fallthrough */
        case step_C:
                        if (plainchar == plaintextend)
                        {
@@ -140,7 +142,6 @@ static int base64_encode_blockend(char* code_out, base64_encodestate* state_in)
        case step_A:
                break;
        }
-       *codechar++ = '\n';
        
        return codechar - code_out;
 }
@@ -190,6 +191,7 @@ static int base64_decode_block(const char* code_in, const int length_in, unsigne
                                fragment = (char)base64_decode_value(*codechar++);
                        } while (fragment < 0);
                        *plainchar    = (fragment & 0x03f) << 2;
+                       /* fallthrough */
        case step_b:
                        do {
                                if (codechar == code_in+length_in)
@@ -202,6 +204,7 @@ static int base64_decode_block(const char* code_in, const int length_in, unsigne
                        } while (fragment < 0);
                        *plainchar++ |= (fragment & 0x030) >> 4;
                        *plainchar    = (fragment & 0x00f) << 4;
+                       /* fallthrough */
        case step_c:
                        do {
                                if (codechar == code_in+length_in)
@@ -214,6 +217,7 @@ static int base64_decode_block(const char* code_in, const int length_in, unsigne
                        } while (fragment < 0);
                        *plainchar++ |= (fragment & 0x03c) >> 2;
                        *plainchar    = (fragment & 0x003) << 6;
+                       /* fallthrough */
        case step_d:
                        do {
                                if (codechar == code_in+length_in)
index 8adf9404d643a1b0b55a2af197e7d67e26714411..eb6ed65447d57ef433bbd3127c753a717667ab8c 100644 (file)
@@ -1,22 +1,24 @@
 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], [], [
@@ -75,8 +77,12 @@ AC_ARG_ENABLE(gcrypt,
                           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
@@ -103,8 +109,6 @@ AS_IF([test "x$use_gcrypt" = "xyes"], [
 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]])])
index cb996e870f71cf011bd41b4b159528bb5f35f825..afd9ee1ca17891f334b1471842d65749150882bf 100644 (file)
--- a/crypto.c
+++ b/crypto.c
@@ -24,6 +24,7 @@ freely, subject to the following restrictions:
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
+#include <stddef.h>
 #include <assert.h>
 #include "crypto.h"
 #include "crypto_if.h"
@@ -44,7 +45,7 @@ static struct crypto_interface *ifs[] = {
 #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;
 
@@ -63,7 +64,7 @@ const char *crypto_init(const int ifno)
 
 #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;
 
@@ -71,7 +72,7 @@ unsigned long encrypt(const void *key, const int keylen, const void *pt, void *c
        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;
 
@@ -79,13 +80,13 @@ unsigned long decrypt(const void *key, const int keylen, const void *ct, void *p
        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);
index 8d5e7be2393108e054227fda983f9ca70ce0ea94..56b86070002364f44056faaf458159926008a7cc 100644 (file)
--- a/crypto.h
+++ b/crypto.h
@@ -26,11 +26,11 @@ freely, subject to the following restrictions:
 
 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
index e2c7579794fc707a383b19b917c9ab8430acb001..037ef05a911485ccfe9c95676f4698f1ca7bf1c9 100644 (file)
@@ -26,15 +26,15 @@ freely, subject to the following restrictions:
 
 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);
 };
 
index 5c8621d7f2f55b7aa22b0dc366b3d01f5280e207..05371754d39f293456419048fcdf315ffac3d8a5 100644 (file)
@@ -36,8 +36,8 @@ static const char *gnu_init(void)
        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;
@@ -56,8 +56,8 @@ static unsigned long gnu_encrypt(const void *key, const int keylen, void *iv,
        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;
@@ -76,8 +76,8 @@ static unsigned long gnu_decrypt(const void *key, const int keylen, void *iv,
        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;
@@ -95,9 +95,9 @@ static unsigned long gnu_hash(const void *pt, const int tlen,
        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;
index 4cf0afae3572088262bc3523eb02d5ca4718effa..fbf72b2069ef4d113238f60be848695da14ce6eb 100644 (file)
@@ -37,8 +37,8 @@ static const char *ossl_init(void)
        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;
 
@@ -48,8 +48,8 @@ static unsigned long ossl_encrypt(const void *key, const int keylen, void *iv,
        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;
 
@@ -59,8 +59,8 @@ static unsigned long ossl_decrypt(const void *key, const int keylen, void *iv,
        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;
 
@@ -71,9 +71,9 @@ static unsigned long ossl_hash(const void *pt, const int tlen,
        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;
index 612747ab80913e03d9c5e2cc0e49323b32d79dcf..0a5f1f4393488338fecf9426057ec5e388cc52e0 100644 (file)
@@ -35,11 +35,11 @@ freely, subject to the following restrictions:
 #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);
@@ -49,7 +49,7 @@ token_key(const unsigned char *challenge, const int challengesize)
 
 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);
@@ -197,8 +197,8 @@ int main(int argc, char *argv[])
                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;
index f729fad4a89b15110665620bb0bc2a44e2c473fb..82f08ad301741149b724176ef26b4c5b57c8360e 100644 (file)
@@ -110,11 +110,11 @@ static int pam_get_authtok(pam_handle_t *pamh, int item, const char **authtok,
 #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);
@@ -122,7 +122,7 @@ token_key(const unsigned char *challenge, const int challengesize)
        return ho;
 }
 
-static void update_nonce(char *nonce, const int nonsize)
+static void update_nonce(char *nonce, const size_t nonsize)
 {
        int n = 0;
 
@@ -186,7 +186,7 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags,
        }
 
        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;
index 7f2ccffb6bb2c863112c3aa3fe95ee610669411e..03a9e70e1c5a8a9ed994e53e644ca1683763d7d6 100644 (file)
--- a/pcsc_cr.c
+++ b/pcsc_cr.c
@@ -41,7 +41,8 @@ SCARD_IO_REQUEST pioSendPci;
 
 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;
index 2da8292d754bca5f55f0055503382a377dd0238c..9769c2a7833ed07aa7cd4024047332e263266020 100644 (file)
--- a/pcsc_cr.h
+++ b/pcsc_cr.h
@@ -25,8 +25,8 @@ freely, subject to the following restrictions:
 #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
diff --git a/reader.h b/reader.h
new file mode 100644 (file)
index 0000000..ea46c0d
--- /dev/null
+++ b/reader.h
@@ -0,0 +1,20 @@
+#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
index 2b81bebca52f1048a1ac1b08263e846abc4b226d..8bb781d6d12a56b548dc3557c41a64669b019928 100644 (file)
--- a/serial.c
+++ b/serial.c
@@ -27,15 +27,15 @@ freely, subject to the following restrictions:
 #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;
@@ -44,9 +44,9 @@ void serial_switch(serializer_t *srl, void *buffer, int size)
 }
 
 /* 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;
@@ -57,9 +57,9 @@ int serial_put(serializer_t *srl, const void *item, int 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;
@@ -70,7 +70,7 @@ int serial_get(serializer_t *srl, void **item, int *size)
        return 0;
 }
 
-int serial_size(serializer_t *srl)
+size_t serial_size(serializer_t *srl)
 {
        return srl->cursor - srl->buffer;
 }
index e67edfcfb7def39bfb2d2c3eb70c38aa6bcc3602..65ee24f67ee9b30031e50c933be5b2699e60251a 100644 (file)
--- a/serial.h
+++ b/serial.h
@@ -26,14 +26,14 @@ freely, subject to the following restrictions:
 
 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
index 5a826e812186e7a7873f2ecc4856f09ac4ee6992..cf287fce323951bce8a1d2551c2e384a514b3cba 100644 (file)
@@ -34,11 +34,11 @@ unsigned char secret[] = {
 };
 
 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))) {
@@ -50,11 +50,11 @@ conjure_key(const unsigned char *challenge, const int challengesize)
 }
 
 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);
@@ -69,11 +69,11 @@ int main(int argc, char *argv[])
        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) {
@@ -88,9 +88,9 @@ int main(int argc, char *argv[])
                        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);
@@ -100,9 +100,9 @@ int main(int argc, char *argv[])
        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);
index 2df9639a6249fadefde82b6cee51b6b8c2de156d..f099be27a259733b41da81d5b3d780997dc7fbd2 100644 (file)
@@ -34,22 +34,23 @@ static unsigned char src[40] = "Quick brown fox jumps over the lazy dog";
 
 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));
 }
index 4f0c3e0aae3de743263296a920f60d407e3bf0f7..2635fea99d9b0707c42a8890681202c33b609274 100644 (file)
@@ -40,10 +40,10 @@ static void usage(const char *const cmd)
 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;
 
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
        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
@@ -85,7 +85,7 @@ int main(int argc, char *argv[])
        
        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;
index f9099a278698c6fb7d5dccaf857c59c671e01850..7199a9c4a09be438b0a52f8afec9231091ef6b88 100644 (file)
@@ -33,7 +33,7 @@ freely, subject to the following restrictions:
 #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");
@@ -76,7 +76,7 @@ int test_sha(int iface)
 {
        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};
@@ -88,7 +88,7 @@ int test_sha(int iface)
                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");
@@ -101,7 +101,7 @@ int test_hmac(int iface)
 {
        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,
@@ -115,7 +115,7 @@ int test_hmac(int iface)
                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");
index 49f157e295d61a42d1762890d2bc7a6ed31a2d2f..bb2fa4609567c9e82ae8e58c784220bfe24bc69c 100644 (file)
@@ -50,19 +50,19 @@ int main(int argc, char *argv[])
                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;
                        }
                }
index b5bed3e06d0fe5da41293903ded63b15f281c8dc..68d8cf23260d1cc9aa04bb86f2217f77925fc37b 100644 (file)
@@ -34,8 +34,8 @@ static const char *tom_init(void)
        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;
@@ -49,8 +49,8 @@ static unsigned long tom_encrypt(const void *key, const int keylen, void *iv,
        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;
@@ -64,8 +64,8 @@ static unsigned long tom_decrypt(const void *key, const int keylen, void *iv,
        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;
@@ -77,9 +77,9 @@ static unsigned long tom_hash(const void *pt, const int tlen,
        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;