Skip to content

Commit 33270bf

Browse files
committed
Add a couple comments pointing to particular sections of RFC6979.
1 parent 2632019 commit 33270bf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/hash_impl.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,28 +207,32 @@ static void secp256k1_rfc6979_hmac_sha256_initialize(secp256k1_rfc6979_hmac_sha2
207207
static const unsigned char zero[1] = {0x00};
208208
static const unsigned char one[1] = {0x01};
209209

210-
memset(rng->v, 0x01, 32);
211-
memset(rng->k, 0x00, 32);
210+
memset(rng->v, 0x01, 32); /* RFC6979 3.2.b. */
211+
memset(rng->k, 0x00, 32); /* RFC6979 3.2.c. */
212212

213+
/* RFC6979 3.2.d. */
213214
secp256k1_hmac_sha256_initialize(&hmac, rng->k, 32);
214215
secp256k1_hmac_sha256_write(&hmac, rng->v, 32);
215216
secp256k1_hmac_sha256_write(&hmac, zero, 1);
216217
secp256k1_hmac_sha256_write(&hmac, key, keylen);
217218
secp256k1_hmac_sha256_write(&hmac, msg, msglen);
218219
if (rnd && rndlen) {
220+
/* RFC6979 3.6 "Additional data". */
219221
secp256k1_hmac_sha256_write(&hmac, rnd, rndlen);
220222
}
221223
secp256k1_hmac_sha256_finalize(&hmac, rng->k);
222224
secp256k1_hmac_sha256_initialize(&hmac, rng->k, 32);
223225
secp256k1_hmac_sha256_write(&hmac, rng->v, 32);
224226
secp256k1_hmac_sha256_finalize(&hmac, rng->v);
225227

228+
/* RFC6979 3.2.f. */
226229
secp256k1_hmac_sha256_initialize(&hmac, rng->k, 32);
227230
secp256k1_hmac_sha256_write(&hmac, rng->v, 32);
228231
secp256k1_hmac_sha256_write(&hmac, one, 1);
229232
secp256k1_hmac_sha256_write(&hmac, key, keylen);
230233
secp256k1_hmac_sha256_write(&hmac, msg, msglen);
231234
if (rnd && rndlen) {
235+
/* RFC6979 3.6 "Additional data". */
232236
secp256k1_hmac_sha256_write(&hmac, rnd, rndlen);
233237
}
234238
secp256k1_hmac_sha256_finalize(&hmac, rng->k);
@@ -239,6 +243,7 @@ static void secp256k1_rfc6979_hmac_sha256_initialize(secp256k1_rfc6979_hmac_sha2
239243
}
240244

241245
static void secp256k1_rfc6979_hmac_sha256_generate(secp256k1_rfc6979_hmac_sha256_t *rng, unsigned char *out, size_t outlen) {
246+
/* RFC6979 3.2.h. */
242247
static const unsigned char zero[1] = {0x00};
243248
if (rng->retry) {
244249
secp256k1_hmac_sha256_t hmac;

0 commit comments

Comments
 (0)