/*
* test-pbkdf2.c
* -------------
* Test program for PBKDF2.
*
* Authors: Rob Austein
* Copyright (c) 2015, NORDUnet A/S
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the NORDUnet nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <hal.h>
/* PBKDF2 HMAC-SHA-1 test cases from RFC 6070. */
/* 'password' */
static const uint8_t pbkdf2_tc_1_password[] = { /* 8 bytes */
0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64
};
/* 'salt' */
static const uint8_t pbkdf2_tc_1_salt[] = { /* 4 bytes */
0x73, 0x61, 0x6c, 0x74
};
static const unsigned pbkdf2_tc_1_count = 1;
static const uint8_t pbkdf2_tc_1_DK[] = { /* 20 bytes */
0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71, 0xf3, 0xa9, 0xb5, 0x24,
0xaf, 0x60, 0x12, 0x06, 0x2f, 0xe0, 0x37, 0xa6
};
/* 'password' */
static const uint8_t pbkdf2_tc_2_password[] = { /* 8 bytes */
0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64
};
/* 'salt' */
static const uint8_t pbkdf2_tc_2_salt[] = { /* 4 bytes */
0x73, 0x61, 0x6c, 0x74
};
static const unsigned pbkdf2_tc_2_count = 2;
static const uint8_t pbkdf2_tc_2_DK[] = { /* 20 bytes */
0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c, 0xcd, 0x1e, 0xd9, 0x2a,
0xce, 0x1d, 0x41, 0xf0, 0xd8, 0xde, 0x89, 0x57
};
/* 'password' */
static const uint8_t pbkdf2_tc_3_password[] = { /* 8 bytes */
0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64
};
/* 'salt' */
static const uint8_t pbkdf2_tc_3_salt[] = { /* 4 bytes */
0x73, 0x61, 0x6c, 0x74
};
static const unsigned pbkdf2_tc_3_count = 4096;
static const uint8_t pbkdf2_tc_3_DK[] = { /* 20 bytes */
0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a, 0xbe, 0xad, 0x49, 0xd9,
0x26, 0xf7, 0x21, 0xd0, 0x65, 0xa4, 0x29, 0xc1
};
/* 'password' */
static const uint8_t pbkdf2_tc_4_password[] = { /* 8 bytes */
0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64
};
/* 'salt' */
static const uint8_t pbkdf2_tc_4_salt[] = { /* 4 bytes */
0x73, 0x61, 0x6c, 0x74
};
static const unsigned pbkdf2_tc_4_count = 16777216;
static const uint8_t pbkdf2_tc_4_DK[] = { /* 20 bytes */
0xee, 0xfe, 0x3d, 0x61, 0xcd, 0x4d, 0xa4, 0xe4, 0xe9, 0x94, 0x5b, 0x3d,
0x6b, 0xa2, 0x15, 0x8c, 0x26, 0x34, 0xe9, 0x84
};
/* 'passwordPASSWORDpassword' */
static const uint8_t pbkdf2_tc_5_password[] = { /* 24 bytes */
0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x50, 0x41, 0x53, 0x53,
0x57, 0x4f, 0x52, 0x44, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64
};
/* 'saltSALTsaltSALTsaltSALTsaltSALTsalt' */
static