1178825Sdfr/* 2233294Sstas * Copyright (c) 2005 Kungliga Tekniska H��gskolan 3233294Sstas * (Royal Institute of Technology, Stockholm, Sweden). 4233294Sstas * All rights reserved. 5178825Sdfr * 6233294Sstas * Redistribution and use in source and binary forms, with or without 7233294Sstas * modification, are permitted provided that the following conditions 8233294Sstas * are met: 9178825Sdfr * 10233294Sstas * 1. Redistributions of source code must retain the above copyright 11233294Sstas * notice, this list of conditions and the following disclaimer. 12178825Sdfr * 13233294Sstas * 2. Redistributions in binary form must reproduce the above copyright 14233294Sstas * notice, this list of conditions and the following disclaimer in the 15233294Sstas * documentation and/or other materials provided with the distribution. 16178825Sdfr * 17178825Sdfr * 3. Neither the name of KTH nor the names of its contributors may be 18178825Sdfr * used to endorse or promote products derived from this software without 19178825Sdfr * specific prior written permission. 20178825Sdfr * 21178825Sdfr * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY 22178825Sdfr * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23178825Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24178825Sdfr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE 25178825Sdfr * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26178825Sdfr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27178825Sdfr * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 28178825Sdfr * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29178825Sdfr * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30178825Sdfr * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 31178825Sdfr * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 32178825Sdfr 33178825Sdfr#include "krb5_locl.h" 34178825Sdfr#include <err.h> 35178825Sdfr#include <getarg.h> 36178825Sdfr 37178825Sdfrstatic void 38178825Sdfrtest_dh2key(int i, 39233294Sstas krb5_context context, 40178825Sdfr const heim_octet_string *dh, 41178825Sdfr const heim_octet_string *c_n, 42178825Sdfr const heim_octet_string *k_n, 43178825Sdfr krb5_enctype etype, 44178825Sdfr const heim_octet_string *result) 45178825Sdfr{ 46178825Sdfr krb5_error_code ret; 47178825Sdfr krb5_keyblock key; 48178825Sdfr 49178825Sdfr ret = _krb5_pk_octetstring2key(context, 50178825Sdfr etype, 51178825Sdfr dh->data, dh->length, 52178825Sdfr c_n, 53178825Sdfr k_n, 54178825Sdfr &key); 55178825Sdfr if (ret != 0) 56178825Sdfr krb5_err(context, 1, ret, "_krb5_pk_octetstring2key: %d", i); 57178825Sdfr 58178825Sdfr if (key.keyvalue.length != result->length || 59178825Sdfr memcmp(key.keyvalue.data, result->data, result->length) != 0) 60178825Sdfr krb5_errx(context, 1, "resulting key wrong: %d", i); 61178825Sdfr 62178825Sdfr krb5_free_keyblock_contents(context, &key); 63178825Sdfr} 64178825Sdfr 65178825Sdfr 66178825Sdfrstruct { 67178825Sdfr krb5_enctype type; 68178825Sdfr krb5_data X; 69178825Sdfr krb5_data key; 70178825Sdfr} tests[] = { 71178825Sdfr /* 0 */ 72178825Sdfr { 73178825Sdfr ETYPE_AES256_CTS_HMAC_SHA1_96, 74178825Sdfr { 75178825Sdfr 256, 76178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 77178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 78178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 79178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 80178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 81178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 82178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 83178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 84178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 85178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 86178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 87178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 88178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 89178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 90178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 91178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 92178825Sdfr }, 93178825Sdfr { 94178825Sdfr 32, 95178825Sdfr "\x5e\xe5\x0d\x67\x5c\x80\x9f\xe5\x9e\x4a\x77\x62\xc5\x4b\x65\x83" 96178825Sdfr "\x75\x47\xea\xfb\x15\x9b\xd8\xcd\xc7\x5f\xfc\xa5\x91\x1e\x4c\x41" 97178825Sdfr } 98178825Sdfr }, 99178825Sdfr /* 1 */ 100178825Sdfr { 101178825Sdfr ETYPE_AES256_CTS_HMAC_SHA1_96, 102178825Sdfr { 103178825Sdfr 128, 104178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 105178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 106178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 107178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 108178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 109178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 110178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 111178825Sdfr "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 112178825Sdfr }, 113178825Sdfr { 114178825Sdfr 32, 115178825Sdfr "\xac\xf7\x70\x7c\x08\x97\x3d\xdf\xdb\x27\xcd\x36\x14\x42\xcc\xfb" 116178825Sdfr "\xa3\x55\xc8\x88\x4c\xb4\x72\xf3\x7d\xa6\x36\xd0\x7d\x56\x78\x7e" 117178825Sdfr } 118178825Sdfr }, 119178825Sdfr /* 2 */ 120178825Sdfr { 121178825Sdfr ETYPE_AES256_CTS_HMAC_SHA1_96, 122178825Sdfr { 123178825Sdfr 128, 124178825Sdfr "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" 125178825Sdfr "\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e" 126178825Sdfr "\x0f\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d" 127178825Sdfr "\x0e\x0f\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c" 128178825Sdfr "\x0d\x0e\x0f\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b" 129178825Sdfr "\x0c\x0d\x0e\x0f\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a" 130178825Sdfr "\x0b\x0c\x0d\x0e\x0f\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09" 131178825Sdfr "\x0a\x0b\x0c\x0d\x0e\x0f\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08" 132178825Sdfr }, 133178825Sdfr { 134178825Sdfr 32, 135178825Sdfr "\xc4\x42\xda\x58\x5f\xcb\x80\xe4\x3b\x47\x94\x6f\x25\x40\x93\xe3" 136178825Sdfr "\x73\x29\xd9\x90\x01\x38\x0d\xb7\x83\x71\xdb\x3a\xcf\x5c\x79\x7e" 137178825Sdfr } 138178825Sdfr }, 139178825Sdfr /* 3 */ 140178825Sdfr { 141178825Sdfr ETYPE_AES256_CTS_HMAC_SHA1_96, 142178825Sdfr { 143178825Sdfr 77, 144178825Sdfr "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" 145178825Sdfr "\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e" 146178825Sdfr "\x0f\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d" 147178825Sdfr "\x0e\x0f\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c" 148178825Sdfr "\x0d\x0e\x0f\x10\x00\x01\x02\x03" 149178825Sdfr "\x04\x05\x06\x07\x08" 150178825Sdfr }, 151178825Sdfr { 152178825Sdfr 32, 153178825Sdfr "\x00\x53\x95\x3b\x84\xc8\x96\xf4\xeb\x38\x5c\x3f\x2e\x75\x1c\x4a" 154178825Sdfr "\x59\x0e\xd6\xff\xad\xca\x6f\xf6\x4f\x47\xeb\xeb\x8d\x78\x0f\xfc" 155178825Sdfr } 156178825Sdfr } 157178825Sdfr}; 158178825Sdfr 159178825Sdfr 160178825Sdfrstatic int version_flag = 0; 161178825Sdfrstatic int help_flag = 0; 162178825Sdfr 163178825Sdfrstatic struct getargs args[] = { 164178825Sdfr {"version", 0, arg_flag, &version_flag, 165178825Sdfr "print version", NULL }, 166178825Sdfr {"help", 0, arg_flag, &help_flag, 167178825Sdfr NULL, NULL } 168178825Sdfr}; 169178825Sdfr 170178825Sdfrstatic void 171178825Sdfrusage (int ret) 172178825Sdfr{ 173178825Sdfr arg_printusage (args, 174178825Sdfr sizeof(args)/sizeof(*args), 175178825Sdfr NULL, 176178825Sdfr ""); 177178825Sdfr exit (ret); 178178825Sdfr} 179178825Sdfr 180178825Sdfr 181178825Sdfrint 182178825Sdfrmain(int argc, char **argv) 183178825Sdfr{ 184178825Sdfr krb5_context context; 185178825Sdfr krb5_error_code ret; 186178825Sdfr int i, optidx = 0; 187178825Sdfr 188178825Sdfr setprogname(argv[0]); 189178825Sdfr 190178825Sdfr if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx)) 191178825Sdfr usage(1); 192233294Sstas 193178825Sdfr if (help_flag) 194178825Sdfr usage (0); 195178825Sdfr 196178825Sdfr if(version_flag){ 197178825Sdfr print_version(NULL); 198178825Sdfr exit(0); 199178825Sdfr } 200178825Sdfr 201178825Sdfr argc -= optidx; 202178825Sdfr argv += optidx; 203178825Sdfr 204178825Sdfr ret = krb5_init_context(&context); 205178825Sdfr if (ret) 206178825Sdfr errx (1, "krb5_init_context failed: %d", ret); 207178825Sdfr 208178825Sdfr for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) { 209233294Sstas test_dh2key(i, context, &tests[i].X, NULL, NULL, 210178825Sdfr tests[i].type, &tests[i].key); 211178825Sdfr } 212178825Sdfr 213178825Sdfr krb5_free_context(context); 214178825Sdfr 215178825Sdfr return 0; 216178825Sdfr} 217