Commit d5cf39a0 authored by Niels Möller's avatar Niels Möller

* testsuite/sha1-test.m4: New file.

* testsuite/des-test.m4: New file.

Rev: src/nettle/testsuite/des-test.m4:1.1
Rev: src/nettle/testsuite/sha1-test.m4:1.1
parent 0e2568ff
#include "des.h"
BEGIN_TEST
struct des_ctx ctx;
uint8_t msg[DES_BLOCK_SIZE];
uint8_t cipher[DES_BLOCK_SIZE];
uint8_t clear[DES_BLOCK_SIZE];
H(msg, "00 00 00 00 00 00 00 00");
if (!des_set_key(&ctx, H("01 01 01 01 01 01 01 80")))
FAIL;
des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, msg);
if (!MEMEQ(DES_BLOCK_SIZE, cipher,
H("9C C6 2D F4 3B 6E ED 74")))
FAIL;
des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(DES_BLOCK_SIZE, msg, clear))
FAIL;
H(msg, "00 00 00 00 00 00 00 40");
if (!des_set_key(&ctx, H("80 01 01 01 01 01 01 01")))
FAIL;
des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, msg);
if (!MEMEQ(DES_BLOCK_SIZE, cipher,
H("A3 80 E0 2A 6B E5 46 96")))
FAIL;
des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(DES_BLOCK_SIZE, msg, clear))
FAIL;
H(msg, "00 00 00 00 00 00 00 00");
if (!des_set_key(&ctx, H("08 19 2A 3B 4C 5D 6E 7F")))
FAIL;
des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, msg);
if (!MEMEQ(DES_BLOCK_SIZE, cipher,
H("25 DD AC 3E 96 17 64 67")))
FAIL;
des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(DES_BLOCK_SIZE, msg, clear))
FAIL;
if (!des_set_key(&ctx, H("01 23 45 67 89 AB CD EF")))
FAIL;
des_encrypt(&ctx, DES_BLOCK_SIZE, cipher, "Now is t");
if (!MEMEQ(DES_BLOCK_SIZE, cipher,
H("3F A4 0E 8A 98 4D 48 15")))
FAIL;
des_decrypt(&ctx, DES_BLOCK_SIZE, clear, cipher);
if (!MEMEQ(DES_BLOCK_SIZE, "Now is t", clear))
FAIL;
/* Parity check */
if (des_set_key(&ctx, H("01 01 01 01 01 01 01 00"))
|| (ctx.status != DES_BAD_PARITY))
FAIL;
/* Weak key check */
if (des_set_key(&ctx, H("01 01 01 01 01 01 01 01"))
|| (ctx.status != DES_WEAK_KEY))
FAIL;
if (des_set_key(&ctx, H("01 FE 01 FE 01 FE 01 FE"))
|| (ctx.status != DES_WEAK_KEY))
FAIL;
if (des_set_key(&ctx, H("FE E0 FE E0 FE F1 FE F1"))
|| (ctx.status != DES_WEAK_KEY))
FAIL;
#include "sha1.h"
BEGIN_TEST
struct sha1_ctx ctx;
uint8_t digest[SHA1_DIGEST_SIZE];
sha1_init(&ctx);
sha1_final(&ctx);
sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest);
if (!MEMEQ(SHA1_DIGEST_SIZE, digest,
H("DA39A3EE5E6B4B0D 3255BFEF95601890 AFD80709")))
FAIL;
sha1_init(&ctx);
sha1_update(&ctx, 1, "a");
sha1_final(&ctx);
sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest);
if (!MEMEQ(SHA1_DIGEST_SIZE, digest,
H("86F7E437FAA5A7FC E15D1DDCB9EAEAEA 377667B8")))
FAIL;
memset(digest, 0, SHA1_DIGEST_SIZE);
sha1_digest(&ctx, SHA1_DIGEST_SIZE - 1, digest);
if (!MEMEQ(SHA1_DIGEST_SIZE, digest,
H("86F7E437FAA5A7FC E15D1DDCB9EAEAEA 37766700")))
FAIL;
sha1_init(&ctx);
sha1_update(&ctx, 1, "a");
sha1_final(&ctx);
sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest);
if (!MEMEQ(SHA1_DIGEST_SIZE, digest,
H("86F7E437FAA5A7FC E15D1DDCB9EAEAEA 377667B8")))
FAIL;
sha1_init(&ctx);
sha1_update(&ctx, 3, "abc");
sha1_final(&ctx);
sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest);
if (!MEMEQ(SHA1_DIGEST_SIZE, digest,
H("A9993E364706816A BA3E25717850C26C 9CD0D89D")))
FAIL;
sha1_init(&ctx);
sha1_update(&ctx, 26, "abcdefghijklmnopqrstuvwxyz");
sha1_final(&ctx);
sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest);
if (!MEMEQ(SHA1_DIGEST_SIZE, digest,
H("32D10C7B8CF96570 CA04CE37F2A19D84 240D3A89")))
FAIL;
sha1_init(&ctx);
sha1_update(&ctx, 14, "message digest");
sha1_final(&ctx);
sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest);
if (!MEMEQ(SHA1_DIGEST_SIZE, digest,
H("C12252CEDA8BE899 4D5FA0290A47231C 1D16AAE3")))
FAIL;
sha1_init(&ctx);
sha1_update(&ctx, 62, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
sha1_final(&ctx);
sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest);
if (!MEMEQ(SHA1_DIGEST_SIZE, digest,
H("761C457BF73B14D2 7E9E9265C46F4B4D DA11F940")))
FAIL;
sha1_init(&ctx);
sha1_update(&ctx, 80, "1234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890");
sha1_final(&ctx);
sha1_digest(&ctx, SHA1_DIGEST_SIZE, digest);
if (!MEMEQ(SHA1_DIGEST_SIZE, digest,
H("50ABF5706A150990 A08B2C5EA40FA0E5 85554732")))
FAIL;
Markdown is supported
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