diff options
author | Nick Mathewson <nickm@torproject.org> | 2003-05-01 00:53:46 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2003-05-01 00:53:46 +0000 |
commit | 6af79f3a03fe23342ff4e41d0405238905643b67 (patch) | |
tree | b7af162280bf474db782fff1d94c0a63c4ecf072 /src/or | |
parent | e0d734eb69c61123bd7940bdd6ad00676bc0ae99 (diff) | |
download | tor-6af79f3a03fe23342ff4e41d0405238905643b67.tar tor-6af79f3a03fe23342ff4e41d0405238905643b67.tar.gz |
Basic diffie-helman wrappers with fixed modulus and tests
svn:r257
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/test.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/or/test.c b/src/or/test.c index 8b53d7d22..17ad0ecf6 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -229,8 +229,41 @@ test_buffers() { buf_free(buf2); } +void +test_crypto_dh() +{ + crypto_dh_env_t *dh1, *dh2; + char p1[CRYPTO_DH_SIZE]; + char p2[CRYPTO_DH_SIZE]; + char s1[CRYPTO_DH_SIZE]; + char s2[CRYPTO_DH_SIZE]; + + dh1 = crypto_dh_new(); + dh2 = crypto_dh_new(); + test_eq(crypto_dh_get_bytes(dh1), CRYPTO_DH_SIZE); + test_eq(crypto_dh_get_bytes(dh2), CRYPTO_DH_SIZE); + + memset(p1, 0, CRYPTO_DH_SIZE); + memset(p2, 0, CRYPTO_DH_SIZE); + test_memeq(p1, p2, CRYPTO_DH_SIZE); + test_assert(! crypto_dh_get_public(dh1, p1, CRYPTO_DH_SIZE)); + test_memneq(p1, p2, CRYPTO_DH_SIZE); + test_assert(! crypto_dh_get_public(dh2, p2, CRYPTO_DH_SIZE)); + test_memneq(p1, p2, CRYPTO_DH_SIZE); + + memset(s1, 0, CRYPTO_DH_SIZE); + memset(s2, 0, CRYPTO_DH_SIZE); + test_assert(! crypto_dh_compute_secret(dh1, p2, CRYPTO_DH_SIZE, s1)); + test_assert(! crypto_dh_compute_secret(dh2, p1, CRYPTO_DH_SIZE, s2)); + test_memeq(s1, s2, CRYPTO_DH_SIZE); + + crypto_dh_free(dh1); + crypto_dh_free(dh2); +} + void -test_crypto() { +test_crypto() +{ crypto_cipher_env_t *env1, *env2; crypto_pk_env_t *pk1, *pk2; char *data1, *data2, *data3, *cp; @@ -441,6 +474,7 @@ main(int c, char**v) { puts("========================== Buffers ========================="); test_buffers(); puts("========================== Crypto =========================="); + test_crypto_dh(); test_crypto(); /* this seg faults :( */ puts("\n========================== Util ============================"); test_util(); |