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
16 #include <openssl/evp.h>
17 #include <openssl/sha.h>
20 # include <openssl/ebcdic.h>
23 static char test[][80] = {
25 { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" }
28 static char *ret[] = {
29 "a9993e364706816aba3e25717850c26c9cd0d89d",
30 "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
33 static char *bigret = "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
35 static char *pt(unsigned char *md)
40 for (i = 0; i < SHA_DIGEST_LENGTH; i++)
41 sprintf(&(buf[i * 2]), "%02x", md[i]);
45 static int test_sha1(int i)
48 unsigned char md[SHA_DIGEST_LENGTH];
49 const size_t tlen = strlen(test[i]);
56 # ifdef CHARSET_EBCDIC
57 ebcdic2ascii(test[i], test[i], tlen);
59 if (!TEST_true(EVP_Digest(test[i], tlen, md, NULL, EVP_sha1(), NULL))
60 || !TEST_str_eq(pt(md), ret[i]))
69 static int test_sha1_big(void)
71 static unsigned char buf[1000];
73 unsigned char md[SHA_DIGEST_LENGTH];
74 int i, testresult = 0;
80 memset(buf, 'a', 1000);
82 ebcdic2ascii(buf, buf, 1000);
83 #endif /* CHARSET_EBCDIC */
84 if (!TEST_true(EVP_DigestInit_ex(c, EVP_sha1(), NULL)))
86 for (i = 0; i < 1000; i++)
87 if (!TEST_true(EVP_DigestUpdate(c, buf, 1000)))
89 if (!TEST_true(EVP_DigestFinal_ex(c, md, NULL)))
92 if (!TEST_str_eq(pt(md), bigret))
101 void register_tests(void)
103 ADD_ALL_TESTS(test_sha1, OSSL_NELEM(test));
104 ADD_TEST(test_sha1_big);