os/ossrv/ssl/tsrc/crypto_test/src/sha256t.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* crypto/sha/sha256t.c */
sl@0
     2
/* ====================================================================
sl@0
     3
 * Copyright (c) 2004 The OpenSSL Project.  All rights reserved.
sl@0
     4
 * ====================================================================
sl@0
     5
 */
sl@0
     6
/*
sl@0
     7
 © Portions copyright (c) 2010 Nokia Corporation.  All rights reserved.
sl@0
     8
 */
sl@0
     9
sl@0
    10
#include <stdio.h>
sl@0
    11
#include <string.h>
sl@0
    12
#include <stdlib.h>
sl@0
    13
sl@0
    14
#include <openssl/sha.h>
sl@0
    15
#include <openssl/evp.h>
sl@0
    16
#include <errno.h>
sl@0
    17
sl@0
    18
#ifdef SYMBIAN
sl@0
    19
#ifdef stdin
sl@0
    20
#undef stdin
sl@0
    21
#endif
sl@0
    22
#ifdef stdout
sl@0
    23
#undef stdout
sl@0
    24
#endif
sl@0
    25
#ifdef stderr
sl@0
    26
#undef stderr
sl@0
    27
#endif
sl@0
    28
sl@0
    29
#define stdin fp_stdin
sl@0
    30
#define stdout fp_stdout
sl@0
    31
#define stderr fp_stderr
sl@0
    32
sl@0
    33
extern FILE *fp_stdout;
sl@0
    34
extern FILE *fp_stderr;
sl@0
    35
#endif
sl@0
    36
sl@0
    37
#if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA256)
sl@0
    38
int main(int argc, char *argv[])
sl@0
    39
{
sl@0
    40
    printf("No SHA256 support\n");
sl@0
    41
    return(0);
sl@0
    42
}
sl@0
    43
#else
sl@0
    44
sl@0
    45
unsigned char app_b1[SHA256_DIGEST_LENGTH] = {
sl@0
    46
	0xba,0x78,0x16,0xbf,0x8f,0x01,0xcf,0xea,
sl@0
    47
	0x41,0x41,0x40,0xde,0x5d,0xae,0x22,0x23,
sl@0
    48
	0xb0,0x03,0x61,0xa3,0x96,0x17,0x7a,0x9c,
sl@0
    49
	0xb4,0x10,0xff,0x61,0xf2,0x00,0x15,0xad	};
sl@0
    50
sl@0
    51
unsigned char app_b2[SHA256_DIGEST_LENGTH] = {
sl@0
    52
	0x24,0x8d,0x6a,0x61,0xd2,0x06,0x38,0xb8,
sl@0
    53
	0xe5,0xc0,0x26,0x93,0x0c,0x3e,0x60,0x39,
sl@0
    54
	0xa3,0x3c,0xe4,0x59,0x64,0xff,0x21,0x67,
sl@0
    55
	0xf6,0xec,0xed,0xd4,0x19,0xdb,0x06,0xc1	};
sl@0
    56
sl@0
    57
unsigned char app_b3[SHA256_DIGEST_LENGTH] = {
sl@0
    58
	0xcd,0xc7,0x6e,0x5c,0x99,0x14,0xfb,0x92,
sl@0
    59
	0x81,0xa1,0xc7,0xe2,0x84,0xd7,0x3e,0x67,
sl@0
    60
	0xf1,0x80,0x9a,0x48,0xa4,0x97,0x20,0x0e,
sl@0
    61
	0x04,0x6d,0x39,0xcc,0xc7,0x11,0x2c,0xd0	};
sl@0
    62
sl@0
    63
unsigned char addenum_1[SHA224_DIGEST_LENGTH] = {
sl@0
    64
	0x23,0x09,0x7d,0x22,0x34,0x05,0xd8,0x22,
sl@0
    65
	0x86,0x42,0xa4,0x77,0xbd,0xa2,0x55,0xb3,
sl@0
    66
	0x2a,0xad,0xbc,0xe4,0xbd,0xa0,0xb3,0xf7,
sl@0
    67
	0xe3,0x6c,0x9d,0xa7 };
sl@0
    68
sl@0
    69
unsigned char addenum_2[SHA224_DIGEST_LENGTH] = {
sl@0
    70
	0x75,0x38,0x8b,0x16,0x51,0x27,0x76,0xcc,
sl@0
    71
	0x5d,0xba,0x5d,0xa1,0xfd,0x89,0x01,0x50,
sl@0
    72
	0xb0,0xc6,0x45,0x5c,0xb4,0xf5,0x8b,0x19,
sl@0
    73
	0x52,0x52,0x25,0x25 };
sl@0
    74
sl@0
    75
unsigned char addenum_3[SHA224_DIGEST_LENGTH] = {
sl@0
    76
	0x20,0x79,0x46,0x55,0x98,0x0c,0x91,0xd8,
sl@0
    77
	0xbb,0xb4,0xc1,0xea,0x97,0x61,0x8a,0x4b,
sl@0
    78
	0xf0,0x3f,0x42,0x58,0x19,0x48,0xb2,0xee,
sl@0
    79
	0x4e,0xe7,0xad,0x67 };
sl@0
    80
sl@0
    81
#ifndef SYMBIAN
sl@0
    82
int main (int argc,char **argv)
sl@0
    83
#else
sl@0
    84
int sha256_main(int argc,char **argv)
sl@0
    85
#endif
sl@0
    86
{ unsigned char md[SHA256_DIGEST_LENGTH];
sl@0
    87
  int		i;
sl@0
    88
  EVP_MD_CTX	evp;
sl@0
    89
sl@0
    90
    fprintf(stdout,"Testing SHA-256 ");
sl@0
    91
sl@0
    92
    EVP_Digest ("abc",3,md,NULL,EVP_sha256(),NULL);
sl@0
    93
    if (memcmp(md,app_b1,sizeof(app_b1)))
sl@0
    94
    {	fflush(stdout);
sl@0
    95
	fprintf(stderr,"\nTEST 1 of 3 failed.\n");
sl@0
    96
	return 1;
sl@0
    97
    }
sl@0
    98
    else
sl@0
    99
	fprintf(stdout,"."); fflush(stdout);
sl@0
   100
sl@0
   101
    EVP_Digest ("abcdbcde""cdefdefg""efghfghi""ghijhijk"
sl@0
   102
		"ijkljklm""klmnlmno""mnopnopq",56,md,NULL,EVP_sha256(),NULL);
sl@0
   103
    if (memcmp(md,app_b2,sizeof(app_b2)))
sl@0
   104
    {	fflush(stdout);
sl@0
   105
	fprintf(stderr,"\nTEST 2 of 3 failed.\n");
sl@0
   106
	return 1;
sl@0
   107
    }
sl@0
   108
    else
sl@0
   109
	fprintf(stdout,"."); fflush(stdout);
sl@0
   110
sl@0
   111
    EVP_MD_CTX_init (&evp);
sl@0
   112
    EVP_DigestInit_ex (&evp,EVP_sha256(),NULL);
sl@0
   113
    for (i=0;i<1000000;i+=160)
sl@0
   114
	EVP_DigestUpdate (&evp,	"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
sl@0
   115
				"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
sl@0
   116
				"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
sl@0
   117
				"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
sl@0
   118
				"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
sl@0
   119
				(1000000-i)<160?1000000-i:160);
sl@0
   120
    EVP_DigestFinal_ex (&evp,md,NULL);
sl@0
   121
    EVP_MD_CTX_cleanup (&evp);
sl@0
   122
sl@0
   123
    if (memcmp(md,app_b3,sizeof(app_b3)))
sl@0
   124
    {	fflush(stdout);
sl@0
   125
	fprintf(stderr,"\nTEST 3 of 3 failed.\n");
sl@0
   126
	return 1;
sl@0
   127
    }
sl@0
   128
    else
sl@0
   129
	fprintf(stdout,"."); fflush(stdout);
sl@0
   130
sl@0
   131
    fprintf(stdout," passed.\n"); fflush(stdout);
sl@0
   132
sl@0
   133
    fprintf(stdout,"Testing SHA-224 ");
sl@0
   134
sl@0
   135
    EVP_Digest ("abc",3,md,NULL,EVP_sha224(),NULL);
sl@0
   136
    if (memcmp(md,addenum_1,sizeof(addenum_1)))
sl@0
   137
    {	fflush(stdout);
sl@0
   138
	fprintf(stderr,"\nTEST 1 of 3 failed.\n");
sl@0
   139
	return 1;
sl@0
   140
    }
sl@0
   141
    else
sl@0
   142
	fprintf(stdout,"."); fflush(stdout);
sl@0
   143
sl@0
   144
    EVP_Digest ("abcdbcde""cdefdefg""efghfghi""ghijhijk"
sl@0
   145
		"ijkljklm""klmnlmno""mnopnopq",56,md,NULL,EVP_sha224(),NULL);
sl@0
   146
    if (memcmp(md,addenum_2,sizeof(addenum_2)))
sl@0
   147
    {	fflush(stdout);
sl@0
   148
	fprintf(stderr,"\nTEST 2 of 3 failed.\n");
sl@0
   149
	return 1;
sl@0
   150
    }
sl@0
   151
    else
sl@0
   152
	fprintf(stdout,"."); fflush(stdout);
sl@0
   153
sl@0
   154
    EVP_MD_CTX_init (&evp);
sl@0
   155
    EVP_DigestInit_ex (&evp,EVP_sha224(),NULL);
sl@0
   156
    for (i=0;i<1000000;i+=64)
sl@0
   157
	EVP_DigestUpdate (&evp,	"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
sl@0
   158
				"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
sl@0
   159
				(1000000-i)<64?1000000-i:64);
sl@0
   160
    EVP_DigestFinal_ex (&evp,md,NULL);
sl@0
   161
    EVP_MD_CTX_cleanup (&evp);
sl@0
   162
sl@0
   163
    if (memcmp(md,addenum_3,sizeof(addenum_3)))
sl@0
   164
    {	fflush(stdout);
sl@0
   165
	fprintf(stderr,"\nTEST 3 of 3 failed.\n");
sl@0
   166
	return 1;
sl@0
   167
    }
sl@0
   168
    else
sl@0
   169
	fprintf(stdout,"."); fflush(stdout);
sl@0
   170
sl@0
   171
    fprintf(stdout," passed.\n"); fflush(stdout);
sl@0
   172
sl@0
   173
  return 0;
sl@0
   174
}
sl@0
   175
#endif