2 * Copyright 1995-2016 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
15 #include <openssl/evp.h>
16 #include <openssl/sha.h>
19 # include <openssl/ebcdic.h>
22 static char test[][80] = {
24 { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" }
27 static char *ret[] = {
28 "a9993e364706816aba3e25717850c26c9cd0d89d",
29 "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
32 static char *bigret = "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
34 static char *pt(unsigned char *md);
35 int main(int argc, char *argv[])
40 static unsigned char buf[1000];
43 unsigned char md[SHA_DIGEST_LENGTH];
47 for (i = 0; i < OSSL_NELEM(test); i++) {
48 # ifdef CHARSET_EBCDIC
49 ebcdic2ascii(test[i], test[i], strlen(test[i]));
51 EVP_Digest(test[i], strlen(test[i]), md, NULL, EVP_sha1(), NULL);
53 if (strcmp(p, (char *)*R) != 0) {
54 printf("error calculating SHA1 on '%s'\n", test[i]);
55 printf("got %s instead of %s\n", p, *R);
58 printf("test %d ok\n", i + 1);
62 memset(buf, 'a', 1000);
64 ebcdic2ascii(buf, buf, 1000);
65 #endif /* CHARSET_EBCDIC */
66 EVP_DigestInit_ex(c, EVP_sha1(), NULL);
67 for (i = 0; i < 1000; i++)
68 EVP_DigestUpdate(c, buf, 1000);
69 EVP_DigestFinal_ex(c, md, NULL);
73 if (strcmp(p, r) != 0) {
74 printf("error calculating SHA1 on 'a' * 1000\n");
75 printf("got %s instead of %s\n", p, r);
78 printf("test 3 ok\n");
85 static char *pt(unsigned char *md)
90 for (i = 0; i < SHA_DIGEST_LENGTH; i++)
91 sprintf(&(buf[i * 2]), "%02x", md[i]);