gost_test.c revision bd911976d51f102751848568ccf56592fd5f6d77
/*
* Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id$ */
/* ! \file */
#include <config.h>
#include <atf-c.h>
#include <stdio.h>
#include <string.h>
#include "dnstest.h"
#ifdef HAVE_OPENSSL_GOST
#include "../dst_gost.h"
#endif
#ifdef HAVE_PKCS11_GOST
#include "../dst_gost.h"
#include <pk11/internal.h>
#define WANT_GOST_PARAMS
#include <pk11/constants.h>
#endif
#if defined(HAVE_OPENSSL_GOST) || defined(HAVE_PKCS11_GOST)
/*
* Test data from Wikipedia GOST (hash function)
*/
unsigned char digest[ISC_GOST_DIGESTLENGTH];
unsigned char buffer[1024];
const char *s;
int i = 0;
/*
* Precondition: a hexadecimal number in *d, the length of that number in len,
* and a pointer to a character array to put the output (*out).
* Postcondition: A String representation of the given hexadecimal number is
* placed into the array *out
*
* 'out' MUST point to an array of at least len * 2 + 1
*
* Return values: ISC_R_SUCCESS if the operation is sucessful
*/
static isc_result_t
char c_ret[] = "AA";
unsigned int j;
out[0] = '\0';
for (j = 0; j < len; j++) {
}
return (ISC_R_SUCCESS);
}
#define TEST_INPUT(x) (x), sizeof(x)-1
typedef struct hash_testcase {
const char *input;
const char *result;
int repeats;
"GOST R 34.11-94 examples from Wikipedia");
}
/*
* These are the various test vectors. All of these are passed
* through the hash function and the results are compared to the
* result specified here.
*/
hash_testcase_t testcases[] = {
/* Test 1 */
{
TEST_INPUT(""),
"0x981E5F3CA30C841487830F84FB433E1"
"3AC1101569B9C13584AC483234CD656C0",
1
},
/* Test 2 */
{
TEST_INPUT("a"),
"0xE74C52DD282183BF37AF0079C9F7805"
"5715A103F17E3133CEFF1AACF2F403011",
1
},
/* Test 3 */
{
TEST_INPUT("abc"),
"0xB285056DBF18D7392D7677369524DD1"
"4747459ED8143997E163B2986F92FD42C",
1
},
/* Test 4 */
{
TEST_INPUT("message digest"),
"0xBC6041DD2AA401EBFA6E9886734174F"
"EBDB4729AA972D60F549AC39B29721BA0",
1
},
/* Test 5 */
{
TEST_INPUT("The quick brown fox jumps "
"over the lazy dog"),
"0x9004294A361A508C586FE53D1F1B027"
"46765E71B765472786E4770D565830A76",
1
},
/* Test 6 */
{
TEST_INPUT("ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"
"fghijklmnopqrstuvwxyz0123456789"),
"0x73B70A39497DE53A6E08C67B6D4DB85"
"3540F03E9389299D9B0156EF7E85D0F61",
1
},
/* Test 7 */
{
TEST_INPUT("1234567890123456789012345678901"
"2345678901234567890123456789012"
"345678901234567890"),
"0x6BC7B38989B28CF93AE8842BF9D7529"
"05910A7528A61E5BCE0782DE43E610C90",
1
},
/* Test 8 */
{
TEST_INPUT("This is message, length=32 bytes"),
"0x2CEFC2F7B7BDC514E18EA57FA74FF35"
"7E7FA17D652C75F69CB1BE7893EDE48EB",
1
},
/* Test 9 */
{
TEST_INPUT("Suppose the original message "
"has length = 50 bytes"),
"0xC3730C5CBCCACF915AC292676F21E8B"
"D4EF75331D9405E5F1A61DC3130A65011",
1
},
/* Test 10 */
{
"0x1C4AC7614691BBF427FA2316216BE8F"
"10D92EDFD37CD1027514C1008F649C4E8",
128
},
/* Test 11 */
{
"0x8693287AA62F9478F7CB312EC0866B6"
"C4E4A0F11160441E8F4FFCD2715DD554F",
1000000
},
};
}
testcase++;
}
dns_test_end();
}
}
unsigned char privraw[31] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e
};
#ifdef HAVE_OPENSSL_GOST
unsigned char rbuf[32];
unsigned char privasn1[70] = {
0x30, 0x44, 0x02, 0x01, 0x00, 0x30, 0x1c, 0x06,
0x06, 0x2a, 0x85, 0x03, 0x02, 0x02, 0x13, 0x30,
0x12, 0x06, 0x07, 0x2a, 0x85, 0x03, 0x02, 0x02,
0x23, 0x01, 0x06, 0x07, 0x2a, 0x85, 0x03, 0x02,
0x02, 0x1e, 0x01, 0x04, 0x21, 0x02, 0x1f, 0x01,
0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11,
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
0x1a, 0x1b, 0x1c, 0x1d, 0x1e
};
unsigned char abuf[71];
unsigned char gost_dummy_key[71] = {
0x30, 0x45, 0x02, 0x01, 0x00, 0x30, 0x1c, 0x06,
0x06, 0x2a, 0x85, 0x03, 0x02, 0x02, 0x13, 0x30,
0x12, 0x06, 0x07, 0x2a, 0x85, 0x03, 0x02, 0x02,
0x23, 0x01, 0x06, 0x07, 0x2a, 0x85, 0x03, 0x02,
0x02, 0x1e, 0x01, 0x04, 0x22, 0x02, 0x20, 0x1b,
0x3f, 0x94, 0xf7, 0x1a, 0x5f, 0x2f, 0xe7, 0xe5,
0x74, 0x0b, 0x8c, 0xd4, 0xb7, 0x18, 0xdd, 0x65,
0x68, 0x26, 0xd1, 0x54, 0xfb, 0x77, 0xba, 0x63,
0x72, 0xd9, 0xf0, 0x63, 0x87, 0xe0, 0xd6
};
const unsigned char *p;
int len;
unsigned char *q;
/* raw parse */
p = gost_dummy_key;
(long) sizeof(gost_dummy_key)) != NULL);
/* asn1 tofile */
q = abuf;
/* asn1 parse */
p = privasn1;
dns_test_end();
#else
{
(CK_ULONG) sizeof(pk11_gost_a_paramset) },
(CK_ULONG) sizeof(pk11_gost_paramset) }
};
/* create the private key */
CKR_OK);
/* sign something */
siglen = 0;
dns_test_end();
#endif
};
#else
}
atf_tc_skip("GOST not available");
}
#endif
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
#if defined(HAVE_OPENSSL_GOST) || defined(HAVE_PKCS11_GOST)
#else
#endif
return (atf_no_error());
}