/****************************************************************/
/* 802.11i HMAC-SHA-1 Test Code */
/* Copyright (c) 2002, David Johnston */
/* Author: David Johnston */
/* Email (home): dj@deadhat.com */
/* Email (general): david.johnston@ieee.org */
/* Version 0.1 */
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* */
/* This code implements the NIST HMAC-SHA-1 algorithm as used */
/* the IEEE 802.11i security spec. */
/* */
/* Supported message length is limited to 4096 characters */
/* ToDo: */
/* Sort out endian tolerance. Currently little endian. */
/****************************************************************/
#include <stdlib.h>
#include <stdio.h>
#define MAX_MESSAGE_LENGTH 4096
/********************************************/
/* Test Cases */
/* An array of test cases taken from the */
/* 802.11i specification. */
/********************************************/
#define NUM_TEST_CASES 10
int test_case_length[] = {9,8,28,50,50,20,54,73,54,73};
unsigned char test_cases[] =
{
/* "Sample #1" */
0x53,0x61,0x6d,0x70,0x6c,0x65,0x20,0x23,0x31,
/* "Hi There" */
0x48,0x69,0x20,0x54,0x68,0x65,0x72,0x65,
/* "what do ya want for nothing?" */
0x77,0x68,0x61,0x74,0x20,0x64,0x6f,0x20,0x79,0x61,
0x20,0x77,0x61,0x6e,0x74,0x20,0x66,0x6f,0x72,0x20,
0x6e,0x6f,0x74,0x68,0x69,0x6e,0x67,0x3f,
0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,
0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,
0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,
0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,
0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,
/* "Test With Truncation" */
0x54,0x65,0x73,0x74,0x20,0x57,0x69,0x74,0x68,0x20,0x54,0x72,0x75,0x6e,0x63,0x61,
0x74,0x69,0x6f,0x6e,
/* "Test Using Larger Than Block-Size Key - Hash Key First" */
0x54,0x65,0x73,0x74,0x20,0x55,0x73,0x69,0x6e,0x67,0x20,0x4c,0x61,0x72,0x67,0x65,
0x72,0x20,0x54,0x68,0x61,0x6e,0x20,0x42,0x6c,0x6f,0x63,0x6b,0x2d,0x53,0x69,0x7a,
0x65,0x20,0x4b,0x65,0x79,0x20,0x2d,0x20,0x48,0x61,0x73,0x68,0x20,0x4b,0x65,0x79,
0x20,0x46,0x69,0x72,0x73,0x74,
/* "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data" */
0x54,0x65,0x73,0x74,0x20,0x55,0x73,0x69,0x6e,0x67,0x20,0x4c,0x61,0x72,0x67,0x65,
0x72,0x20,0x54,0x68,0x61,0x6e,0x20,0x42,0x6c,0x6f,0x63,0x6b,0x2d,0x53,0x69,0x7a,
0x65,0x20,0x4b,0x65,0x79,0x20,0x61,0x6e,0x64,0x20,0x4c,0x61,0x72,0x67,0x65,0x72,
0x20,0x54,0x68,0x61,0x6e,0x20,0x4f,0x6e,0x65,0x20,0x42,0x6c,0x6f,0x63,0x6b,0x2d,
0x53,0x69,0x7a,0x65,0x20,0x44,0x61,0x74,0x61,
/* "Test Using Larger Than Block-Size Key - Hash Key First" */
0x54,0x65,0x73,0x74,0x20,0x55,0x73,0x69,0x6e,0x67,0x20,0x4c,0x61,0x72,0x67,0x65,
0x72,0x20,0x54,0x68,0x61,0x6e,0x20,0x42,0x6c,0x6f,0x63,0x6b,0x2d,0x53,0x69,0x7a,
0x65,0x20,0x4b,0x65,0x79,0x20,0x2d,0x20,0x48,0x61,0x73,0x68,0x20,0x4b,0x65,0x79,
0x20,0x46,0x69,0x72,0x73,0x74,
/* "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data" */
0x54,0x65,0x73,0x74,0x20,0x55,0x73,0x69,0x6e,0x67,0x20,0x4c,0x61,0x72,0x67,0x65,
0x72,0x20,0x54,0x68,0x61,0x6e,0x20,0x42,0x6c,0x6f,0x63,0x6b,0x2d,0x53,0x69,0x7a,
0x65,0x20,0x4b,0x65,0x79,0x20,0x61,0x6e,0x64,0x20,0x4c,0x61,0x72,0x67,0x65,0x72,
0x20,0x54,0x68,0x61,0x6e,0x20,0x4f,0x6e,0x65,0x20,0x42,0x6c,0x6f,0x63,0x6b,0x2d,
0x53,0x69,0x7a,0x65,0x20,0x44,0x61,0x74,0x61
};
int key_lengths[] =
{
64, 20,4,20,25,20,80,80,80,80
};
unsigned char keys[] =
{
0x00,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,0x1f,
0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,
0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,
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