aboutsummaryrefslogtreecommitdiffstats
path: root/test/chacha_internal_test.c
diff options
context:
space:
mode:
authorPauli <paul.dale@oracle.com>2017-04-12 13:45:02 +1000
committerMatt Caswell <matt@openssl.org>2017-04-12 11:51:34 +0100
commitbea4ac2b2e6499e1f0844c9dbacd670955d94ccb (patch)
tree5d8e064d3a380214823f5b2c663384a962837238 /test/chacha_internal_test.c
parentc983bc4fb2a501df36b95da160ef9002c15cb8fe (diff)
downloadopenssl-bea4ac2b2e6499e1f0844c9dbacd670955d94ccb.tar.gz
Update the internal chacha test to use the framework
Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3195)
Diffstat (limited to 'test/chacha_internal_test.c')
-rw-r--r--test/chacha_internal_test.c49
1 files changed, 24 insertions, 25 deletions
diff --git a/test/chacha_internal_test.c b/test/chacha_internal_test.c
index 9b2f361478..0c0be9b387 100644
--- a/test/chacha_internal_test.c
+++ b/test/chacha_internal_test.c
@@ -12,10 +12,10 @@
* complete 32-byte blocks. This test goes per byte...
*/
-#include <stdio.h>
#include <string.h>
-
#include <openssl/opensslconf.h>
+#include "test_main.h"
+#include "testutil.h"
#include "internal/chacha.h"
const static unsigned int key[] = {
@@ -158,34 +158,33 @@ const static unsigned char ref[] = {
0xd3, 0x3e, 0xa2, 0x15, 0x5d, 0x10, 0x5d, 0x4e
};
-int main(void)
+static int test_cha_cha_internal(int n)
{
unsigned char buf[sizeof(ref)];
- unsigned int i,j;
- int ret = 0;
-
-#ifdef CPUID_OBJ
- OPENSSL_cpuid_setup();
-#endif
+ unsigned int i = n + 1, j;
- for (i = 1; i <= sizeof(ref); i++) {
- memset(buf, 0, i);
- memcpy(buf + i, ref + i, sizeof(ref) - i);
+ memset(buf, 0, i);
+ memcpy(buf + i, ref + i, sizeof(ref) - i);
- ChaCha20_ctr32(buf, buf, i, key, ivp);
+ ChaCha20_ctr32(buf, buf, i, key, ivp);
- /*
- * Idea behind checking for whole sizeof(ref) is that if
- * ChaCha20_ctr32 oversteps i-th byte, then we'd know
- */
- for (j = 0; j < sizeof(ref); j++) {
- if (buf[j] != ref[j]) {
- fprintf(stderr, "%u failed at %u (%02x)\n", i, j, buf[j]);
- ret = 1;
- break;
- }
+ /*
+ * Idea behind checking for whole sizeof(ref) is that if
+ * ChaCha20_ctr32 oversteps i-th byte, then we'd know
+ */
+ for (j = 0; j < sizeof(ref); j++)
+ if (!TEST_uchar_eq(buf[j], ref[j])) {
+ TEST_info("%d failed at %u (%02x)\n", i, j, buf[j]);
+ return 0;
}
- }
+ return 1;
+}
+
+void register_tests(void)
+{
+#ifdef CPUID_OBJ
+ OPENSSL_cpuid_setup();
+#endif
- return ret;
+ ADD_ALL_TESTS(test_cha_cha_internal, sizeof(ref));
}