{
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;
}
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;
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;
}
int i, rc;
serializer_t srl;
- if ((rc = serial_init(&srl, buffer, sizeof(buffer)))) {
- printf("serial_init rc=%d\n", rc);
- return 1;
- }
+ serial_init(&srl, buffer, sizeof(buffer));
for (i = 0; in[i]; i++) {
int size = strlen(in[i]);
if ((rc = serial_put(&srl, in[i], size)) != size) {
return 1;
}
printf("serialized size=%d\n", serial_size(&srl));
- if ((rc = serial_init(&srl, buffer, sizeof(buffer)))) {
- printf("second serial_init rc=%d\n", rc);
- return 1;
- }
+ serial_init(&srl, buffer, sizeof(buffer));
for (i = 0; i < 4; i++) {
char item[32];
memset(item, 0, sizeof(item));