X-Git-Url: http://www.average.org/gitweb/?p=pam_pcsc_cr.git;a=blobdiff_plain;f=authobj.c;h=2b774abccae724298d35666d94d9fd83ebbf1f7b;hp=3bd9da5f33e4de709fbf52924e680a11fb015fec;hb=4a5da38dfd8b0236564ffe6b70eab1eeb399fff0;hpb=f58e5aa7a6302c73e94f4cb5f5d8a3cbc199e0b3;ds=sidebyside diff --git a/authobj.c b/authobj.c index 3bd9da5..2b774ab 100644 --- a/authobj.c +++ b/authobj.c @@ -13,11 +13,15 @@ int make_challenge(const char *id, const char *pass, const char *nonce, { serializer_t srl; - if (serial_init(&srl, challenge, *challengesize)) return -1; - if (serial_put(&srl, id, strlen(id)) != strlen(id)) return -2; - if (serial_put(&srl, pass, strlen(pass)) != strlen(pass)) return -3; - if (serial_put(&srl, nonce, strlen(nonce)) != strlen(nonce)) return -4; - if (serial_put(&srl, NULL, 0) != 0) return -5; + serial_init(&srl, challenge, *challengesize); + if (serial_put(&srl, id, strlen(id)) != strlen(id)) + return aoe_serial; + if (serial_put(&srl, pass, strlen(pass)) != strlen(pass)) + return aoe_serial; + if (serial_put(&srl, nonce, strlen(nonce)) != strlen(nonce)) + return aoe_serial; + if (serial_put(&srl, NULL, 0) != 0) + return aoe_serial; *challengesize = serial_size(&srl); return 0; } @@ -40,27 +44,27 @@ int make_authobj(const char *id, const char *pass, const char *nonce, datasize = ((secsize + paysize + HASHSIZE * 4 * sizeof(short) - 1) / CBLKSIZE + 1) * CBLKSIZE; data = alloca(datasize); - if (serial_init(&srl, data, datasize)) return -1; - if (serial_put(&srl, secret, secsize) != secsize) return -2; - if (serial_put(&srl, payload, paysize) != paysize) return -3; + serial_init(&srl, data, datasize); + if (serial_put(&srl, secret, secsize) != secsize) return aoe_serial; + if (serial_put(&srl, payload, paysize) != paysize) return aoe_serial; if (hash(data, serial_size(&srl), datahash, &datahashsize)) - return -4; + return aoe_size; if (serial_put(&srl, datahash, datahashsize) != datahashsize) - return -5; - if (serial_put(&srl, NULL, 0) != 0) return -6; + return aoe_serial; + if (serial_put(&srl, NULL, 0) != 0) return aoe_serial; datasize = ((serial_size(&srl) -1) / CBLKSIZE + 1) * CBLKSIZE; challengesize = ((strlen(id) + strlen(pass) + strlen(nonce) + 4 * sizeof(short) - 1) / CBLKSIZE + 1) * CBLKSIZE; challenge = alloca(challengesize); if (make_challenge(id, pass, nonce, challenge, &challengesize)) - return -7; + return aoe_serial; if (hmac(secret, secsize, challenge, challengesize, - key, &keysize)) return -8; + key, &keysize)) return aoe_crypt; - if (*bufsize < datasize) return -9; - if (encrypt(key, CBLKSIZE, data, buffer, datasize)) return -10; + if (*bufsize < datasize) return aoe_size; + if (encrypt(key, CBLKSIZE, data, buffer, datasize)) return aoe_crypt; *bufsize = datasize; return 0; @@ -81,19 +85,20 @@ int parse_authobj(const unsigned char *key, const int keysize, int theirhashsize = HASHSIZE; if (decrypt(key, CBLKSIZE, buffer, data, datasize)) - return -1; - if (serial_init(&srl, data, datasize)) return -2; + return aoe_crypt; + serial_init(&srl, data, datasize); tsize = *secsize; *secsize = serial_get(&srl, secret, tsize); - if (*secsize > tsize || *secsize <= 0) return -3; + if (*secsize > tsize || *secsize <= 0) return aoe_serial; tsize = *paysize; *paysize = serial_get(&srl, payload, tsize); - if (*paysize > tsize || *paysize <= 0) return -4; - if (hash(data, serial_size(&srl), myhash, &myhashsize)) return -5; + if (*paysize > tsize || *paysize <= 0) return aoe_serial; + if (hash(data, serial_size(&srl), myhash, &myhashsize)) + return aoe_crypt; theirhashsize = serial_get(&srl, theirhash, theirhashsize); - if (theirhashsize != HASHSIZE) return -6; + if (theirhashsize != HASHSIZE) return aoe_data; if ((myhashsize != theirhashsize) || - memcmp(myhash, theirhash, myhashsize)) - return -7; + memcmp(myhash, theirhash, myhashsize)) + return aoe_data; return 0; }