os/ossrv/ssl/tsrc/crypto_test/src/sha512t.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/sha512t.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 <openssl/crypto.h>
sl@0
    17
#include <errno.h>
sl@0
    18
sl@0
    19
#ifdef SYMBIAN
sl@0
    20
#ifdef stdin
sl@0
    21
#undef stdin
sl@0
    22
#endif
sl@0
    23
#ifdef stdout
sl@0
    24
#undef stdout
sl@0
    25
#endif
sl@0
    26
#ifdef stderr
sl@0
    27
#undef stderr
sl@0
    28
#endif
sl@0
    29
sl@0
    30
#define stdin fp_stdin
sl@0
    31
#define stdout fp_stdout
sl@0
    32
#define stderr fp_stderr
sl@0
    33
sl@0
    34
extern FILE *fp_stdout;
sl@0
    35
extern FILE *fp_stderr;
sl@0
    36
#endif
sl@0
    37
sl@0
    38
#if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA512)
sl@0
    39
int main(int argc, char *argv[])
sl@0
    40
{
sl@0
    41
    printf("No SHA512 support\n");
sl@0
    42
    return(0);
sl@0
    43
}
sl@0
    44
#else
sl@0
    45
sl@0
    46
unsigned char app_c1[SHA512_DIGEST_LENGTH] = {
sl@0
    47
	0xdd,0xaf,0x35,0xa1,0x93,0x61,0x7a,0xba,
sl@0
    48
	0xcc,0x41,0x73,0x49,0xae,0x20,0x41,0x31,
sl@0
    49
	0x12,0xe6,0xfa,0x4e,0x89,0xa9,0x7e,0xa2,
sl@0
    50
	0x0a,0x9e,0xee,0xe6,0x4b,0x55,0xd3,0x9a,
sl@0
    51
	0x21,0x92,0x99,0x2a,0x27,0x4f,0xc1,0xa8,
sl@0
    52
	0x36,0xba,0x3c,0x23,0xa3,0xfe,0xeb,0xbd,
sl@0
    53
	0x45,0x4d,0x44,0x23,0x64,0x3c,0xe8,0x0e,
sl@0
    54
	0x2a,0x9a,0xc9,0x4f,0xa5,0x4c,0xa4,0x9f };
sl@0
    55
sl@0
    56
unsigned char app_c2[SHA512_DIGEST_LENGTH] = {
sl@0
    57
	0x8e,0x95,0x9b,0x75,0xda,0xe3,0x13,0xda,
sl@0
    58
	0x8c,0xf4,0xf7,0x28,0x14,0xfc,0x14,0x3f,
sl@0
    59
	0x8f,0x77,0x79,0xc6,0xeb,0x9f,0x7f,0xa1,
sl@0
    60
	0x72,0x99,0xae,0xad,0xb6,0x88,0x90,0x18,
sl@0
    61
	0x50,0x1d,0x28,0x9e,0x49,0x00,0xf7,0xe4,
sl@0
    62
	0x33,0x1b,0x99,0xde,0xc4,0xb5,0x43,0x3a,
sl@0
    63
	0xc7,0xd3,0x29,0xee,0xb6,0xdd,0x26,0x54,
sl@0
    64
	0x5e,0x96,0xe5,0x5b,0x87,0x4b,0xe9,0x09 };
sl@0
    65
sl@0
    66
unsigned char app_c3[SHA512_DIGEST_LENGTH] = {
sl@0
    67
	0xe7,0x18,0x48,0x3d,0x0c,0xe7,0x69,0x64,
sl@0
    68
	0x4e,0x2e,0x42,0xc7,0xbc,0x15,0xb4,0x63,
sl@0
    69
	0x8e,0x1f,0x98,0xb1,0x3b,0x20,0x44,0x28,
sl@0
    70
	0x56,0x32,0xa8,0x03,0xaf,0xa9,0x73,0xeb,
sl@0
    71
	0xde,0x0f,0xf2,0x44,0x87,0x7e,0xa6,0x0a,
sl@0
    72
	0x4c,0xb0,0x43,0x2c,0xe5,0x77,0xc3,0x1b,
sl@0
    73
	0xeb,0x00,0x9c,0x5c,0x2c,0x49,0xaa,0x2e,
sl@0
    74
	0x4e,0xad,0xb2,0x17,0xad,0x8c,0xc0,0x9b };
sl@0
    75
sl@0
    76
unsigned char app_d1[SHA384_DIGEST_LENGTH] = {
sl@0
    77
	0xcb,0x00,0x75,0x3f,0x45,0xa3,0x5e,0x8b,
sl@0
    78
	0xb5,0xa0,0x3d,0x69,0x9a,0xc6,0x50,0x07,
sl@0
    79
	0x27,0x2c,0x32,0xab,0x0e,0xde,0xd1,0x63,
sl@0
    80
	0x1a,0x8b,0x60,0x5a,0x43,0xff,0x5b,0xed,
sl@0
    81
	0x80,0x86,0x07,0x2b,0xa1,0xe7,0xcc,0x23,
sl@0
    82
	0x58,0xba,0xec,0xa1,0x34,0xc8,0x25,0xa7 };
sl@0
    83
sl@0
    84
unsigned char app_d2[SHA384_DIGEST_LENGTH] = {
sl@0
    85
	0x09,0x33,0x0c,0x33,0xf7,0x11,0x47,0xe8,
sl@0
    86
	0x3d,0x19,0x2f,0xc7,0x82,0xcd,0x1b,0x47,
sl@0
    87
	0x53,0x11,0x1b,0x17,0x3b,0x3b,0x05,0xd2,
sl@0
    88
	0x2f,0xa0,0x80,0x86,0xe3,0xb0,0xf7,0x12,
sl@0
    89
	0xfc,0xc7,0xc7,0x1a,0x55,0x7e,0x2d,0xb9,
sl@0
    90
	0x66,0xc3,0xe9,0xfa,0x91,0x74,0x60,0x39 };
sl@0
    91
sl@0
    92
unsigned char app_d3[SHA384_DIGEST_LENGTH] = {
sl@0
    93
	0x9d,0x0e,0x18,0x09,0x71,0x64,0x74,0xcb,
sl@0
    94
	0x08,0x6e,0x83,0x4e,0x31,0x0a,0x4a,0x1c,
sl@0
    95
	0xed,0x14,0x9e,0x9c,0x00,0xf2,0x48,0x52,
sl@0
    96
	0x79,0x72,0xce,0xc5,0x70,0x4c,0x2a,0x5b,
sl@0
    97
	0x07,0xb8,0xb3,0xdc,0x38,0xec,0xc4,0xeb,
sl@0
    98
	0xae,0x97,0xdd,0xd8,0x7f,0x3d,0x89,0x85 };
sl@0
    99
sl@0
   100
#ifndef SYMBIAN
sl@0
   101
int main (int argc,char **argv)
sl@0
   102
#else
sl@0
   103
int sha512_main(int argc,char **argv)
sl@0
   104
#endif
sl@0
   105
sl@0
   106
{ unsigned char md[SHA512_DIGEST_LENGTH];
sl@0
   107
  int		i;
sl@0
   108
  EVP_MD_CTX	evp;
sl@0
   109
sl@0
   110
#ifdef OPENSSL_IA32_SSE2
sl@0
   111
    /* Alternative to this is to call OpenSSL_add_all_algorithms...
sl@0
   112
     * The below code is retained exclusively for debugging purposes. */
sl@0
   113
    { char      *env;
sl@0
   114
sl@0
   115
	if ((env=getenv("OPENSSL_ia32cap")))
sl@0
   116
	    OPENSSL_ia32cap = strtoul (env,NULL,0);
sl@0
   117
    }
sl@0
   118
#endif
sl@0
   119
sl@0
   120
    fprintf(stdout,"Testing SHA-512 ");
sl@0
   121
sl@0
   122
    EVP_Digest ("abc",3,md,NULL,EVP_sha512(),NULL);
sl@0
   123
    if (memcmp(md,app_c1,sizeof(app_c1)))
sl@0
   124
    {	fflush(stdout);
sl@0
   125
	fprintf(stderr,"\nTEST 1 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
    EVP_Digest ("abcdefgh""bcdefghi""cdefghij""defghijk"
sl@0
   132
		"efghijkl""fghijklm""ghijklmn""hijklmno"
sl@0
   133
		"ijklmnop""jklmnopq""klmnopqr""lmnopqrs"
sl@0
   134
		"mnopqrst""nopqrstu",112,md,NULL,EVP_sha512(),NULL);
sl@0
   135
    if (memcmp(md,app_c2,sizeof(app_c2)))
sl@0
   136
    {	fflush(stdout);
sl@0
   137
	fprintf(stderr,"\nTEST 2 of 3 failed.\n");
sl@0
   138
	return 1;
sl@0
   139
    }
sl@0
   140
    else
sl@0
   141
	fprintf(stdout,"."); fflush(stdout);
sl@0
   142
sl@0
   143
    EVP_MD_CTX_init (&evp);
sl@0
   144
    EVP_DigestInit_ex (&evp,EVP_sha512(),NULL);
sl@0
   145
    for (i=0;i<1000000;i+=288)
sl@0
   146
	EVP_DigestUpdate (&evp,	"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
sl@0
   147
				"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
sl@0
   148
				"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
sl@0
   149
				"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
sl@0
   150
				"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
sl@0
   151
				"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
sl@0
   152
				"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
sl@0
   153
				"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
sl@0
   154
				"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
sl@0
   155
				(1000000-i)<288?1000000-i:288);
sl@0
   156
    EVP_DigestFinal_ex (&evp,md,NULL);
sl@0
   157
    EVP_MD_CTX_cleanup (&evp);
sl@0
   158
sl@0
   159
    if (memcmp(md,app_c3,sizeof(app_c3)))
sl@0
   160
    {	fflush(stdout);
sl@0
   161
	fprintf(stderr,"\nTEST 3 of 3 failed.\n");
sl@0
   162
	return 1;
sl@0
   163
    }
sl@0
   164
    else
sl@0
   165
	fprintf(stdout,"."); fflush(stdout);
sl@0
   166
sl@0
   167
    fprintf(stdout," passed.\n"); fflush(stdout);
sl@0
   168
sl@0
   169
    fprintf(stdout,"Testing SHA-384 ");
sl@0
   170
sl@0
   171
    EVP_Digest ("abc",3,md,NULL,EVP_sha384(),NULL);
sl@0
   172
    if (memcmp(md,app_d1,sizeof(app_d1)))
sl@0
   173
    {	fflush(stdout);
sl@0
   174
	fprintf(stderr,"\nTEST 1 of 3 failed.\n");
sl@0
   175
	return 1;
sl@0
   176
    }
sl@0
   177
    else
sl@0
   178
	fprintf(stdout,"."); fflush(stdout);
sl@0
   179
sl@0
   180
    EVP_Digest ("abcdefgh""bcdefghi""cdefghij""defghijk"
sl@0
   181
		"efghijkl""fghijklm""ghijklmn""hijklmno"
sl@0
   182
		"ijklmnop""jklmnopq""klmnopqr""lmnopqrs"
sl@0
   183
		"mnopqrst""nopqrstu",112,md,NULL,EVP_sha384(),NULL);
sl@0
   184
    if (memcmp(md,app_d2,sizeof(app_d2)))
sl@0
   185
    {	fflush(stdout);
sl@0
   186
	fprintf(stderr,"\nTEST 2 of 3 failed.\n");
sl@0
   187
	return 1;
sl@0
   188
    }
sl@0
   189
    else
sl@0
   190
	fprintf(stdout,"."); fflush(stdout);
sl@0
   191
sl@0
   192
    EVP_MD_CTX_init (&evp);
sl@0
   193
    EVP_DigestInit_ex (&evp,EVP_sha384(),NULL);
sl@0
   194
    for (i=0;i<1000000;i+=64)
sl@0
   195
	EVP_DigestUpdate (&evp,	"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
sl@0
   196
				"aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
sl@0
   197
				(1000000-i)<64?1000000-i:64);
sl@0
   198
    EVP_DigestFinal_ex (&evp,md,NULL);
sl@0
   199
    EVP_MD_CTX_cleanup (&evp);
sl@0
   200
sl@0
   201
    if (memcmp(md,app_d3,sizeof(app_d3)))
sl@0
   202
    {	fflush(stdout);
sl@0
   203
	fprintf(stderr,"\nTEST 3 of 3 failed.\n");
sl@0
   204
	return 1;
sl@0
   205
    }
sl@0
   206
    else
sl@0
   207
	fprintf(stdout,"."); fflush(stdout);
sl@0
   208
sl@0
   209
    fprintf(stdout," passed.\n"); fflush(stdout);
sl@0
   210
sl@0
   211
  return 0;
sl@0
   212
}
sl@0
   213
#endif