diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/sha1/sha1test.c | 101 |
1 files changed, 49 insertions, 52 deletions
diff --git a/src/regress/lib/libcrypto/sha1/sha1test.c b/src/regress/lib/libcrypto/sha1/sha1test.c index 537454851b..f1cf09d552 100644 --- a/src/regress/lib/libcrypto/sha1/sha1test.c +++ b/src/regress/lib/libcrypto/sha1/sha1test.c | |||
| @@ -1,25 +1,25 @@ | |||
| 1 | /* $OpenBSD: sha1test.c,v 1.4 2021/11/18 15:23:24 tb Exp $ */ | 1 | /* $OpenBSD: sha1test.c,v 1.5 2021/12/29 22:53:04 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| 5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
| 6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
| 7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
| 8 | * | 8 | * |
| 9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
| 10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 15 | * | 15 | * |
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
| 18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
| 19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
| 20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
| 21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
| 22 | * | 22 | * |
| 23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
| 24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
| 25 | * are met: | 25 | * are met: |
| @@ -34,10 +34,10 @@ | |||
| 34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
| 36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 40 | * | 40 | * |
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| @@ -49,7 +49,7 @@ | |||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
| 52 | * | 52 | * |
| 53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
| @@ -63,26 +63,27 @@ | |||
| 63 | #include <openssl/evp.h> | 63 | #include <openssl/evp.h> |
| 64 | #include <openssl/sha.h> | 64 | #include <openssl/sha.h> |
| 65 | 65 | ||
| 66 | static char *test[]={ | 66 | static char *test[] = { |
| 67 | "abc", | 67 | "abc", |
| 68 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | 68 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", |
| 69 | NULL, | 69 | NULL, |
| 70 | }; | 70 | }; |
| 71 | 71 | ||
| 72 | static char *ret[]={ | 72 | static char *ret[] = { |
| 73 | "a9993e364706816aba3e25717850c26c9cd0d89d", | 73 | "a9993e364706816aba3e25717850c26c9cd0d89d", |
| 74 | "84983e441c3bd26ebaae4aa1f95129e5e54670f1", | 74 | "84983e441c3bd26ebaae4aa1f95129e5e54670f1", |
| 75 | }; | 75 | }; |
| 76 | static char *bigret= | 76 | static char *bigret = |
| 77 | "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; | 77 | "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; |
| 78 | 78 | ||
| 79 | static char *pt(unsigned char *md); | 79 | static char *pt(unsigned char *md); |
| 80 | int main(int argc, char *argv[]) | 80 | int |
| 81 | { | 81 | main(int argc, char *argv[]) |
| 82 | int i,err=0; | 82 | { |
| 83 | char **P,**R; | 83 | int i, err = 0; |
| 84 | char **P, **R; | ||
| 84 | static unsigned char buf[1000]; | 85 | static unsigned char buf[1000]; |
| 85 | char *p,*r; | 86 | char *p, *r; |
| 86 | EVP_MD_CTX *c; | 87 | EVP_MD_CTX *c; |
| 87 | unsigned char md[SHA_DIGEST_LENGTH]; | 88 | unsigned char md[SHA_DIGEST_LENGTH]; |
| 88 | 89 | ||
| @@ -90,53 +91,49 @@ int main(int argc, char *argv[]) | |||
| 90 | printf("EVP_MD_CTX_new() failed\n"); | 91 | printf("EVP_MD_CTX_new() failed\n"); |
| 91 | return 1; | 92 | return 1; |
| 92 | } | 93 | } |
| 93 | P=test; | 94 | P = test; |
| 94 | R=ret; | 95 | R = ret; |
| 95 | i=1; | 96 | i = 1; |
| 96 | while (*P != NULL) | 97 | while (*P != NULL) { |
| 97 | { | 98 | EVP_Digest(*P, strlen((char *)*P), md, NULL, EVP_sha1(), NULL); |
| 98 | EVP_Digest(*P,strlen((char *)*P),md,NULL,EVP_sha1(), NULL); | 99 | p = pt(md); |
| 99 | p=pt(md); | 100 | if (strcmp(p, (char *)*R) != 0) { |
| 100 | if (strcmp(p,(char *)*R) != 0) | 101 | printf("error calculating SHA1 on '%s'\n", *P); |
| 101 | { | 102 | printf("got %s instead of %s\n", p, *R); |
| 102 | printf("error calculating SHA1 on '%s'\n",*P); | ||
| 103 | printf("got %s instead of %s\n",p,*R); | ||
| 104 | err++; | 103 | err++; |
| 105 | } | 104 | } else |
| 106 | else | 105 | printf("test %d ok\n", i); |
| 107 | printf("test %d ok\n",i); | ||
| 108 | i++; | 106 | i++; |
| 109 | R++; | 107 | R++; |
| 110 | P++; | 108 | P++; |
| 111 | } | 109 | } |
| 112 | 110 | ||
| 113 | memset(buf,'a',1000); | 111 | memset(buf, 'a', 1000); |
| 114 | EVP_DigestInit_ex(c,EVP_sha1(), NULL); | 112 | EVP_DigestInit_ex(c, EVP_sha1(), NULL); |
| 115 | for (i=0; i<1000; i++) | 113 | for (i = 0; i < 1000; i++) |
| 116 | EVP_DigestUpdate(c,buf,1000); | 114 | EVP_DigestUpdate(c, buf, 1000); |
| 117 | EVP_DigestFinal_ex(c,md,NULL); | 115 | EVP_DigestFinal_ex(c, md, NULL); |
| 118 | p=pt(md); | 116 | p = pt(md); |
| 119 | 117 | ||
| 120 | r=bigret; | 118 | r = bigret; |
| 121 | if (strcmp(p,r) != 0) | 119 | if (strcmp(p, r) != 0) { |
| 122 | { | ||
| 123 | printf("error calculating SHA1 on 'a' * 1000\n"); | 120 | printf("error calculating SHA1 on 'a' * 1000\n"); |
| 124 | printf("got %s instead of %s\n",p,r); | 121 | printf("got %s instead of %s\n", p, r); |
| 125 | err++; | 122 | err++; |
| 126 | } | 123 | } else |
| 127 | else | ||
| 128 | printf("test 3 ok\n"); | 124 | printf("test 3 ok\n"); |
| 129 | 125 | ||
| 130 | EVP_MD_CTX_free(c); | 126 | EVP_MD_CTX_free(c); |
| 131 | exit(err); | 127 | exit(err); |
| 132 | } | 128 | } |
| 133 | 129 | ||
| 134 | static char *pt(unsigned char *md) | 130 | static char * |
| 135 | { | 131 | pt(unsigned char *md) |
| 132 | { | ||
| 136 | int i; | 133 | int i; |
| 137 | static char buf[80]; | 134 | static char buf[80]; |
| 138 | 135 | ||
| 139 | for (i=0; i<SHA_DIGEST_LENGTH; i++) | 136 | for (i = 0; i < SHA_DIGEST_LENGTH; i++) |
| 140 | snprintf(buf + i*2, sizeof(buf) - i*2, "%02x",md[i]); | 137 | snprintf(buf + i*2, sizeof(buf) - i*2, "%02x", md[i]); |
| 141 | return(buf); | 138 | return (buf); |
| 142 | } | 139 | } |
