2 * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
14 #include "test_main.h"
17 #include <openssl/evp.h>
18 #include <openssl/sha.h>
21 # include <openssl/ebcdic.h>
24 static char test[][80] = {
26 { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" }
29 static char *ret[] = {
30 "a9993e364706816aba3e25717850c26c9cd0d89d",
31 "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
34 static char *bigret = "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
36 static char *pt(unsigned char *md)
41 for (i = 0; i < SHA_DIGEST_LENGTH; i++)
42 sprintf(&(buf[i * 2]), "%02x", md[i]);
46 static int test_sha1(int i)
49 unsigned char md[SHA_DIGEST_LENGTH];
50 const size_t tlen = strlen(test[i]);
57 # ifdef CHARSET_EBCDIC
58 ebcdic2ascii(test[i], test[i], tlen);
60 if (!TEST_true(EVP_Digest(test[i], tlen, md, NULL, EVP_sha1(), NULL))
61 || !TEST_str_eq(pt(md), ret[i]))
70 static int test_sha1_big(void)
72 static unsigned char buf[1000];
74 unsigned char md[SHA_DIGEST_LENGTH];
75 int i, testresult = 0;
81 memset(buf, 'a', 1000);
83 ebcdic2ascii(buf, buf, 1000);
84 #endif /* CHARSET_EBCDIC */
85 if (!TEST_true(EVP_DigestInit_ex(c, EVP_sha1(), NULL)))
87 for (i = 0; i < 1000; i++)
88 if (!TEST_true(EVP_DigestUpdate(c, buf, 1000)))
90 if (!TEST_true(EVP_DigestFinal_ex(c, md, NULL)))
93 if (!TEST_str_eq(pt(md), bigret))
102 void register_tests(void)
104 ADD_ALL_TESTS(test_sha1, OSSL_NELEM(test));
105 ADD_TEST(test_sha1_big);