sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include "utils.h" sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: void printBN(BIGNUM* bn) sl@0: { sl@0: char* text = BN_bn2hex(bn); sl@0: printf("%s", text); sl@0: OPENSSL_free(text); sl@0: } sl@0: sl@0: void printBin(char* data, int len) sl@0: { sl@0: BIGNUM* bn = BN_new(); sl@0: bn = BN_bin2bn(data, len, bn); sl@0: printBN(bn); sl@0: BN_free(bn); sl@0: } sl@0: sl@0: static int vectorNumber = 1; sl@0: sl@0: /** sl@0: * Print the first few lines of the action block. sl@0: */ sl@0: sl@0: void printActionHeader(char* name, char* type) sl@0: { sl@0: printf("\n"); sl@0: printf("\t%s %i (%s)\n", name, vectorNumber++, type); sl@0: printf("\t%s\n", type); sl@0: printf("\t\n"); sl@0: } sl@0: sl@0: /** sl@0: * Print the last few lines of the action block. sl@0: */ sl@0: sl@0: void printActionFooter(BOOL passes) sl@0: { sl@0: printf("\t\n"); sl@0: printf("\t\n"); sl@0: printf("\t\t%s\n", passes ? "ETrue" : "EFalse"); sl@0: printf("\t\n"); sl@0: printf("\n"); sl@0: } sl@0: sl@0: /** sl@0: * Print an element containg hex data. sl@0: */ sl@0: sl@0: void printHexElement(char* name, unsigned char* data, int len) sl@0: { sl@0: printf("\t\t<%s>", name); sl@0: printBin(data, len); sl@0: printf("\n", name); sl@0: } sl@0: sl@0: /** sl@0: * Print an element containg hex data. sl@0: */ sl@0: sl@0: void printBNElement(char* name, BIGNUM* num) sl@0: { sl@0: printf("\t\t<%s>", name); sl@0: printBN(num); sl@0: printf("\n", name); sl@0: } sl@0: sl@0: /** sl@0: * Scramble some data - used for generating tests that we expect to fail. sl@0: */ sl@0: sl@0: void scramble(unsigned char* data, int len) sl@0: { sl@0: int i; sl@0: for (i = 0 ; i < len ; ++ i) sl@0: data[i] ^= i; sl@0: } sl@0: sl@0: /** sl@0: * Print an openssl error and exit. sl@0: */ sl@0: sl@0: void processError() sl@0: { sl@0: unsigned long err = ERR_get_error(); sl@0: ERR_load_crypto_strings(); sl@0: printf("Openssl error: %s\n", ERR_error_string(err, NULL)); sl@0: exit(1); sl@0: } sl@0: sl@0: //////////////////////////////////////////////////////////////////////////////// sl@0: // Random stuff sl@0: //////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: int random_value = 1; sl@0: sl@0: void random_seed(const void* buf, int num) sl@0: { sl@0: } sl@0: sl@0: int random_bytes(unsigned char *buf, int num) sl@0: { sl@0: int i; sl@0: for (i=0; i