2 * Copyright (C) 2017 Cisco Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // @author Changxue Deng <chadeng@cisco.com>
19 #include <openssl/sha.h>
21 #define MABAIN_TEST_KEY_TYPE_INT 0
22 #define MABAIN_TEST_KEY_TYPE_SHA_128 1
23 #define MABAIN_TEST_KEY_TYPE_SHA_256 2
24 #define MABAIN_TEST_KEY_BUFF_SIZE 1024
37 const char* get_key(int key) {
39 case MABAIN_TEST_KEY_TYPE_INT:
40 snprintf(key_buff, MABAIN_TEST_KEY_BUFF_SIZE, "%d", key);
42 case MABAIN_TEST_KEY_TYPE_SHA_128:
44 unsigned char hash[SHA_DIGEST_LENGTH];
47 SHA1_Update(&sha1, (unsigned char*)&key, 4);
48 SHA1_Final(hash, &sha1);
50 for(i = 0; i < SHA_DIGEST_LENGTH; i++)
52 sprintf(key_buff + (i * 2), "%02x", hash[i]);
57 case MABAIN_TEST_KEY_TYPE_SHA_256:
59 unsigned char hash[SHA256_DIGEST_LENGTH];
62 SHA256_Update(&sha256, (unsigned char*)&key, 4);
63 SHA256_Final(hash, &sha256);
65 for(i = 0; i < SHA256_DIGEST_LENGTH; i++)
67 sprintf(key_buff + (i * 2), "%02x", hash[i]);
75 return (const char *) key_buff;
80 char key_buff[MABAIN_TEST_KEY_BUFF_SIZE];