]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/sha1test.c
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 if (!EVP_Digest(test
[i
], strlen(test
[i
]), md
, NULL
, EVP_sha1(),
53 printf("EVP_Digest() error\n");
58 if (strcmp(p
, (char *)*R
) != 0) {
59 printf("error calculating SHA1 on '%s'\n", test
[i
]);
60 printf("got %s instead of %s\n", p
, *R
);
63 printf("test %d ok\n", i
+ 1);
67 memset(buf
, 'a', 1000);
69 ebcdic2ascii(buf
, buf
, 1000);
70 #endif /* CHARSET_EBCDIC */
71 if (!EVP_DigestInit_ex(c
, EVP_sha1(), NULL
)) {
72 printf("EVP_DigestInit_ex() error\n");
76 for (i
= 0; i
< 1000; i
++) {
77 if (!EVP_DigestUpdate(c
, buf
, 1000)) {
78 printf("EVP_DigestUpdate() error\n");
83 if (!EVP_DigestFinal_ex(c
, md
, NULL
)) {
84 printf("EVP_DigestFinal() error\n");
91 if (strcmp(p
, r
) != 0) {
92 printf("error calculating SHA1 on 'a' * 1000\n");
93 printf("got %s instead of %s\n", p
, r
);
96 printf("test 3 ok\n");
103 static char *pt(unsigned char *md
)
108 for (i
= 0; i
< SHA_DIGEST_LENGTH
; i
++)
109 sprintf(&(buf
[i
* 2]), "%02x", md
[i
]);