Commit 0dde2956 authored by Jan Včelák's avatar Jan Včelák 🚀
Browse files

NSEC5 ECC: fixed width encoding of binary numbers

parent 3dc808df
......@@ -28,6 +28,17 @@ static void hex_dump(const uint8_t *data, size_t size)
printf("\n");
}
static void bn2bin_fixed(const BIGNUM *bn, uint8_t *dest, size_t size)
{
int req = BN_num_bytes(bn);
assert(req <= size);
int pad = size - req;
memset(dest, 0, pad);
int wrote = BN_bn2bin(bn, dest + pad);
assert(wrote == req);
}
/*!
* One round of h1.
*/
......@@ -225,9 +236,7 @@ static void nsec5_ecc_sign(const EC_KEY *privkey,
assert(sizeof(c_bin) == C_BIN_LEN);
memcpy(proof + GAMMA_BIN_LEN, c_bin, C_BIN_LEN);
assert(BN_num_bytes(s) == S_BIN_LEN);
r = BN_bn2bin(s, proof + GAMMA_BIN_LEN + C_BIN_LEN);
assert(r == S_BIN_LEN);
bn2bin_fixed(s, proof + GAMMA_BIN_LEN + C_BIN_LEN, S_BIN_LEN);
// cleanup
......@@ -315,8 +324,7 @@ static bool nsec5_ecc_verify(const EC_KEY *pubkey,
h3(group, h, gx, gamma, u, v, hash, sizeof(hash));
uint8_t c_bin[C_BIN_LEN];
assert(BN_num_bytes(c) == sizeof(c_bin));
BN_bn2bin(c, c_bin);
bn2bin_fixed(c, c_bin, sizeof(c_bin));
// clean up
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment