Skip to content

Commit 7c36a3e

Browse files
committed
test_onion: get rid of dummy crypto options.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 32a08ce commit 7c36a3e

File tree

1 file changed

+8
-50
lines changed

1 file changed

+8
-50
lines changed

test/test_onion.c

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
of m, for each message.
3030
*/
3131

32-
//#define EXPORT_FRIENDLY 1 /* No crypto! */
33-
//#define NO_HMAC 1 /* No real hmac */
34-
3532
struct enckey {
3633
struct sha256 k;
3734
};
@@ -72,27 +69,21 @@ static struct hmackey hmackey_from_secret(const unsigned char secret[32])
7269
}
7370

7471

75-
static struct iv iv_from_secret(const unsigned char secret[32], size_t i)
72+
static struct iv iv_from_secret(const unsigned char secret[32])
7673
{
7774
struct iv iv;
7875
struct sha256 sha;
7976
sha_with_seed(secret, 2, &sha);
8077
memcpy(iv.iv, sha.u.u8, sizeof(iv.iv));
81-
#ifdef EXPORT_FRIENDLY
82-
iv.iv[0] = i*2;
83-
#endif
8478
return iv;
8579
}
8680

87-
static struct iv pad_iv_from_secret(const unsigned char secret[32], size_t i)
81+
static struct iv pad_iv_from_secret(const unsigned char secret[32])
8882
{
8983
struct iv iv;
9084
struct sha256 sha;
9185
sha_with_seed(secret, 3, &sha);
9286
memcpy(iv.iv, sha.u.u8, sizeof(iv.iv));
93-
#ifdef EXPORT_FRIENDLY
94-
iv.iv[0] = i*2 + 1;
95-
#endif
9687
return iv;
9788
}
9889

@@ -246,15 +237,6 @@ static struct hop *myhop(const struct onion *onion)
246237
static bool aes_encrypt(void *dst, const void *src, size_t len,
247238
const struct enckey *enckey, const struct iv *iv)
248239
{
249-
#ifdef EXPORT_FRIENDLY
250-
unsigned char *dptr = dst;
251-
const unsigned char *sptr = memcheck(src, len);
252-
size_t i;
253-
254-
for (i = 0; i < len; i++)
255-
dptr[i] = sptr[i] + iv->iv[0] + i / sizeof(struct hop);
256-
return true;
257-
#else
258240
EVP_CIPHER_CTX evpctx;
259241
int outlen;
260242

@@ -275,21 +257,11 @@ static bool aes_encrypt(void *dst, const void *src, size_t len,
275257
return false;
276258
assert(outlen == 0);
277259
return true;
278-
#endif
279260
}
280261

281262
static bool aes_decrypt(void *dst, const void *src, size_t len,
282263
const struct enckey *enckey, const struct iv *iv)
283264
{
284-
#ifdef EXPORT_FRIENDLY
285-
unsigned char *dptr = dst;
286-
const unsigned char *sptr = memcheck(src, len);
287-
size_t i;
288-
289-
for (i = 0; i < len; i++)
290-
dptr[i] = sptr[i] - iv->iv[0] - i / sizeof(struct hop);
291-
return true;
292-
#else
293265
EVP_CIPHER_CTX evpctx;
294266
int outlen;
295267

@@ -310,7 +282,6 @@ static bool aes_decrypt(void *dst, const void *src, size_t len,
310282
return false;
311283
assert(outlen == 0);
312284
return true;
313-
#endif
314285
}
315286

316287
void dump_contents(const void *data, size_t n)
@@ -363,18 +334,6 @@ static void make_hmac(const struct hop *hops, size_t num_hops,
363334
const struct hmackey *hmackey,
364335
struct sha256 *hmac)
365336
{
366-
#ifdef NO_HMAC
367-
/* Copy first byte of message on each hop. */
368-
size_t i;
369-
370-
memset(hmac, 0, sizeof(*hmac));
371-
for (i = 0; i < MAX_HOPS; i++) {
372-
if (i < num_hops)
373-
hmac->u.u8[i] = hops[i].msg[0];
374-
else
375-
hmac->u.u8[i] = padding[i - num_hops].msg[0];
376-
}
377-
#else
378337
HMAC_CTX ctx;
379338
size_t len, padlen;
380339

@@ -387,7 +346,6 @@ static void make_hmac(const struct hop *hops, size_t num_hops,
387346
len = num_hops*sizeof(struct hop) - sizeof(hops->hmac);
388347
HMAC_Update(&ctx, memcheck((unsigned char *)hops, len), len);
389348
HMAC_Final(&ctx, hmac->u.u8, NULL);
390-
#endif
391349
}
392350

393351
void _dump_hex(unsigned char *x, size_t s) {
@@ -449,8 +407,8 @@ bool create_onion(const secp256k1_pubkey pubkey[],
449407

450408
hmackeys[i] = hmackey_from_secret(memcheck(secret, 32));
451409
enckeys[i] = enckey_from_secret(secret);
452-
ivs[i] = iv_from_secret(secret, i);
453-
pad_ivs[i] = pad_iv_from_secret(secret, i);
410+
ivs[i] = iv_from_secret(secret);
411+
pad_ivs[i] = pad_iv_from_secret(secret);
454412
}
455413

456414
/*
@@ -545,7 +503,7 @@ static bool pubkey_parse(const secp256k1_context *ctx,
545503
* Returns enckey and pad_iv for use in unwrap.
546504
*/
547505
bool decrypt_onion(const struct seckey *myseckey, struct onion *onion,
548-
struct enckey *enckey, struct iv *pad_iv, size_t i)
506+
struct enckey *enckey, struct iv *pad_iv)
549507
{
550508
secp256k1_context *ctx;
551509
unsigned char secret[32];
@@ -564,8 +522,8 @@ bool decrypt_onion(const struct seckey *myseckey, struct onion *onion,
564522

565523
hmackey = hmackey_from_secret(secret);
566524
*enckey = enckey_from_secret(secret);
567-
iv = iv_from_secret(secret, i);
568-
*pad_iv = pad_iv_from_secret(secret, i);
525+
iv = iv_from_secret(secret);
526+
*pad_iv = pad_iv_from_secret(secret);
569527

570528
/* Check HMAC. */
571529
#if 0
@@ -661,7 +619,7 @@ int main(int argc, char *argv[])
661619

662620
printf("Decrypting with key %zi\n", i);
663621

664-
if (!decrypt_onion(&seckeys[i], &onion, &enckey, &pad_iv, i))
622+
if (!decrypt_onion(&seckeys[i], &onion, &enckey, &pad_iv))
665623
errx(1, "Decrypting onion for hop %zi", i);
666624
if (strcmp((char *)myhop(&onion)->msg, msgs[i]) != 0)
667625
errx(1, "Bad message for hop %zi", i);

0 commit comments

Comments
 (0)