| 1 |
/* |
| 2 |
* Copyright (c) 2001 Kungliga Tekniska Högskolan |
| 3 |
* (Royal Institute of Technology, Stockholm, Sweden). |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* Redistribution and use in source and binary forms, with or without |
| 7 |
* modification, are permitted provided that the following conditions |
| 8 |
* are met: |
| 9 |
* |
| 10 |
* 1. Redistributions of source code must retain the above copyright |
| 11 |
* notice, this list of conditions and the following disclaimer. |
| 12 |
* |
| 13 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 14 |
* notice, this list of conditions and the following disclaimer in the |
| 15 |
* documentation and/or other materials provided with the distribution. |
| 16 |
* |
| 17 |
* 3. Neither the name of KTH nor the names of its contributors may be |
| 18 |
* used to endorse or promote products derived from this software without |
| 19 |
* specific prior written permission. |
| 20 |
* |
| 21 |
* THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY |
| 22 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 23 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 24 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE |
| 25 |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 26 |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 27 |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 28 |
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ |
| 32 |
|
| 33 |
#include "krb5_locl.h" |
| 34 |
#include <err.h> |
| 35 |
|
| 36 |
enum { MAXSIZE = 48 }; |
| 37 |
|
| 38 |
static struct testcase { |
| 39 |
krb5_enctype enctype; |
| 40 |
unsigned char constant[MAXSIZE]; |
| 41 |
size_t constant_len; |
| 42 |
unsigned char key[MAXSIZE]; |
| 43 |
unsigned char res[MAXSIZE]; |
| 44 |
} tests[] = { |
| 45 |
{ETYPE_AES128_CTS_HMAC_SHA256_128, "test", 4, |
| 46 |
{0x37, 0x05, 0xD9, 0x60, 0x80, 0xC1, 0x77, 0x28, 0xA0, 0xE8, 0x00, 0xEA, 0xB6, 0xE0, 0xD2, 0x3C}, |
| 47 |
{0x9D, 0x18, 0x86, 0x16, 0xF6, 0x38, 0x52, 0xFE, 0x86, 0x91, 0x5B, 0xB8, 0x40, 0xB4, 0xA8, 0x86, |
| 48 |
0xFF, 0x3E, 0x6B, 0xB0, 0xF8, 0x19, 0xB4, 0x9B, 0x89, 0x33, 0x93, 0xD3, 0x93, 0x85, 0x42, 0x95}}, |
| 49 |
{ETYPE_AES256_CTS_HMAC_SHA384_192, "test", 4, |
| 50 |
{0x6D, 0x40, 0x4D, 0x37, 0xFA, 0xF7, 0x9F, 0x9D, 0xF0, 0xD3, 0x35, 0x68, 0xD3, 0x20, 0x66, 0x98, |
| 51 |
0x00, 0xEB, 0x48, 0x36, 0x47, 0x2E, 0xA8, 0xA0, 0x26, 0xD1, 0x6B, 0x71, 0x82, 0x46, 0x0C, 0x52}, |
| 52 |
{0x98, 0x01, 0xF6, 0x9A, 0x36, 0x8C, 0x2B, 0xF6, 0x75, 0xE5, 0x95, 0x21, 0xE1, 0x77, 0xD9, 0xA0, |
| 53 |
0x7F, 0x67, 0xEF, 0xE1, 0xCF, 0xDE, 0x8D, 0x3C, 0x8D, 0x6F, 0x6A, 0x02, 0x56, 0xE3, 0xB1, 0x7D, |
| 54 |
0xB3, 0xC1, 0xB6, 0x2A, 0xD1, 0xB8, 0x55, 0x33, 0x60, 0xD1, 0x73, 0x67, 0xEB, 0x15, 0x14, 0xD2}}, |
| 55 |
{0, {0}, 0, {0}, {0}} |
| 56 |
}; |
| 57 |
|
| 58 |
int |
| 59 |
main(int argc, char **argv) |
| 60 |
{ |
| 61 |
struct testcase *t; |
| 62 |
krb5_context context; |
| 63 |
krb5_error_code ret; |
| 64 |
int val = 0; |
| 65 |
|
| 66 |
ret = krb5_init_context (&context); |
| 67 |
if (ret) |
| 68 |
errx (1, "krb5_init_context failed: %d", ret); |
| 69 |
|
| 70 |
for (t = tests; t->enctype != 0; ++t) { |
| 71 |
krb5_keyblock key; |
| 72 |
krb5_crypto crypto; |
| 73 |
krb5_data constant, prf; |
| 74 |
|
| 75 |
krb5_data_zero(&prf); |
| 76 |
|
| 77 |
key.keytype = t->enctype; |
| 78 |
krb5_enctype_keysize(context, t->enctype, &key.keyvalue.length); |
| 79 |
key.keyvalue.data = t->key; |
| 80 |
|
| 81 |
ret = krb5_crypto_init(context, &key, 0, &crypto); |
| 82 |
if (ret) |
| 83 |
krb5_err (context, 1, ret, "krb5_crypto_init"); |
| 84 |
|
| 85 |
constant.data = t->constant; |
| 86 |
constant.length = t->constant_len; |
| 87 |
|
| 88 |
ret = krb5_crypto_prf(context, crypto, &constant, &prf); |
| 89 |
if (ret) |
| 90 |
krb5_err (context, 1, ret, "krb5_crypto_prf"); |
| 91 |
|
| 92 |
if (memcmp(prf.data, t->res, prf.length) != 0) { |
| 93 |
const unsigned char *p = prf.data; |
| 94 |
int i; |
| 95 |
|
| 96 |
printf ("PRF failed (enctype %d)\n", t->enctype); |
| 97 |
printf ("should be: "); |
| 98 |
for (i = 0; i < prf.length; ++i) |
| 99 |
printf ("%02x", t->res[i]); |
| 100 |
printf ("\nresult was: "); |
| 101 |
for (i = 0; i < prf.length; ++i) |
| 102 |
printf ("%02x", p[i]); |
| 103 |
printf ("\n"); |
| 104 |
val = 1; |
| 105 |
} |
| 106 |
krb5_data_free(&prf); |
| 107 |
krb5_crypto_destroy(context, crypto); |
| 108 |
} |
| 109 |
krb5_free_context(context); |
| 110 |
|
| 111 |
return val; |
| 112 |
} |