]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
* testsuite/arcfour-test.c (test_main): Use test_cipher_stream.
authorNiels Möller <nisse@lysator.liu.se>
Thu, 5 Feb 2004 18:39:55 +0000 (19:39 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Thu, 5 Feb 2004 18:39:55 +0000 (19:39 +0100)
* testsuite/testutils.c (test_cipher_stream): New function, that
tries dividing the input into varying size blocks before
processing.

Rev: src/nettle/testsuite/arcfour-test.c:1.3
Rev: src/nettle/testsuite/testutils.c:1.23
Rev: src/nettle/testsuite/testutils.h:1.19

testsuite/arcfour-test.c
testsuite/testutils.c
testsuite/testutils.h

index 5b1021a813e59c993c6fdf119975b8aa2a6a54ec..f4ec523a5a84060598f761db41538c842d2fd511 100644 (file)
@@ -4,10 +4,10 @@
 int
 test_main(void)
 {
-  test_cipher(&nettle_arcfour128,
-             HL("01234567 89ABCDEF 00000000 00000000"),
-             HL("01234567 89ABCDEF"),
-             H("69723659 1B5242B1"));
+  test_cipher_stream(&nettle_arcfour128,
+                    HL("01234567 89ABCDEF 00000000 00000000"),
+                    HL("01234567 89ABCDEF"),
+                    H("69723659 1B5242B1"));
 
   SUCCESS();
 }
index 418faa1293f5a623c42f8b4e054d84cd17fa9a58..ab7f9259207f23d08ca03f50ac16a37873c70ad7 100644 (file)
@@ -216,6 +216,50 @@ test_cipher_cbc(const struct nettle_cipher *cipher,
     FAIL();
 }
 
+void
+test_cipher_stream(const struct nettle_cipher *cipher,
+                  unsigned key_length,
+                  const uint8_t *key,
+                  unsigned length,
+                  const uint8_t *cleartext,
+                  const uint8_t *ciphertext)
+{
+  unsigned block;
+  
+  void *ctx = alloca(cipher->context_size);
+  uint8_t *data = alloca(length + 1);
+  
+  for (block = 1; block <= length; block++)
+    {
+      unsigned i;
+
+      memset(data, 0x17, length + 1);
+      cipher->set_encrypt_key(ctx, key_length, key);
+
+      for (i = 0; i + block < length; i += block)
+       {
+         cipher->encrypt(ctx, block, data + i, cleartext + i);
+         if (data[i + block] != 0x17)
+           FAIL();
+       }
+      cipher->encrypt(ctx, length - i, data + i, cleartext + i);
+      if (data[length] != 0x17)
+       FAIL();
+      
+      if (!MEMEQ(length, data, ciphertext))
+       FAIL();
+    }
+  
+  cipher->set_decrypt_key(ctx, key_length, key);
+  cipher->decrypt(ctx, length, data, data);
+
+  if (data[length] != 0x17)
+    FAIL();
+
+  if (!MEMEQ(length, data, cleartext))
+    FAIL();
+}
+
 void
 test_hash(const struct nettle_hash *hash,
          unsigned length,
index 2eb02a655a0b9645165334334b88427af697c8e3..65298b239e3140ff614cb4889f8e0488845e2c6d 100644 (file)
@@ -60,6 +60,14 @@ test_cipher_cbc(const struct nettle_cipher *cipher,
                const uint8_t *ciphertext,
                const uint8_t *iv);
 
+void
+test_cipher_stream(const struct nettle_cipher *cipher,
+                  unsigned key_length,
+                  const uint8_t *key,
+                  unsigned length,
+                  const uint8_t *cleartext,
+                  const uint8_t *ciphertext);
+
 void
 test_hash(const struct nettle_hash *hash,
          unsigned length,