]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
(test_cipher_ctr): New function.
authorNiels Möller <nisse@lysator.liu.se>
Sat, 2 Jul 2005 17:02:51 +0000 (19:02 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Sat, 2 Jul 2005 17:02:51 +0000 (19:02 +0200)
Rev: src/nettle/testsuite/testutils.c:1.27
Rev: src/nettle/testsuite/testutils.h:1.22

testsuite/testutils.c
testsuite/testutils.h

index 7ea750ad2fdfa93667fe925d0ddb1d6fbcf8f6fc..801cf882d9a6a2c6e187658a600ac4678a55ba91 100644 (file)
@@ -3,6 +3,7 @@
 #include "testutils.h"
 
 #include "cbc.h"
+#include "ctr.h"
 #include "knuth-lfib.h"
 
 #include <ctype.h>
@@ -224,6 +225,43 @@ test_cipher_cbc(const struct nettle_cipher *cipher,
   free(iv);
 }
 
+void
+test_cipher_ctr(const struct nettle_cipher *cipher,
+               unsigned key_length,
+               const uint8_t *key,
+               unsigned length,
+               const uint8_t *cleartext,
+               const uint8_t *ciphertext,
+               const uint8_t *ictr)
+{
+  void *ctx = xalloc(cipher->context_size);
+  uint8_t *data = xalloc(length);
+  uint8_t *ctr = xalloc(cipher->block_size);
+  
+  cipher->set_encrypt_key(ctx, key_length, key);
+  memcpy(ctr, ictr, cipher->block_size);
+
+  ctr_crypt(ctx, cipher->encrypt,
+           cipher->block_size, ctr,
+           length, data, cleartext);
+
+  if (!MEMEQ(length, data, ciphertext))
+    FAIL();
+
+  memcpy(ctr, ictr, cipher->block_size);
+
+  ctr_crypt(ctx, cipher->encrypt,
+           cipher->block_size, ctr,
+           length, data, data);
+
+  if (!MEMEQ(length, data, cleartext))
+    FAIL();
+
+  free(ctx);
+  free(data);
+  free(ctr);
+}
+
 void
 test_cipher_stream(const struct nettle_cipher *cipher,
                   unsigned key_length,
index a9df1cbaa06fc1c299e63213e515ab91866c8015..46eb5c23e75a88d90407ed85fa470760408148bc 100644 (file)
@@ -63,6 +63,15 @@ test_cipher_cbc(const struct nettle_cipher *cipher,
                const uint8_t *ciphertext,
                const uint8_t *iv);
 
+void
+test_cipher_ctr(const struct nettle_cipher *cipher,
+               unsigned key_length,
+               const uint8_t *key,
+               unsigned length,
+               const uint8_t *cleartext,
+               const uint8_t *ciphertext,
+               const uint8_t *iv);
+
 void
 test_cipher_stream(const struct nettle_cipher *cipher,
                   unsigned key_length,