1 /* $OpenBSD: skeytest.c,v 1.4 2014/03/25 04:29:49 lteo Exp $ */ 2 /* $NetBSD: skeytest.c,v 1.3 2002/02/21 07:38:18 itojun Exp $ */ 3 4 /*- 5 * Copyright (c) 2000 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 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 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 /* 31 * This is a regression test for the S/Key implementation against the data set 32 * from Appendix C of RFC2289 without the MD4 set (MD4 support was removed from 33 * OpenBSD base in March 2014) and with the addition of an RIPEMD-160 set. 34 */ 35 36 #include <stdio.h> 37 #include <string.h> 38 #include "skey.h" 39 40 struct regRes { 41 char *algo, *zero, *one, *nine; 42 }; 43 44 struct regPass { 45 char *passphrase, *seed; 46 struct regRes res[4]; 47 } regPass[] = { 48 { "This is a test.", "TeSt", { 49 { "md5", "9E876134D90499DD", "7965E05436F5029F", "50FE1962C4965880" }, 50 { "rmd160","3A1BFB10A64B4CCD", "39D56BF655E65DE7", "42F84BA862941033" }, 51 { "sha1","BB9E6AE1979D8FF4", "63D936639734385B", "87FEC7768B73CCF9" }, 52 { NULL } } }, 53 { "AbCdEfGhIjK", "alpha1", { 54 { "md5", "87066DD9644BF206", "7CD34C1040ADD14B", "5AA37A81F212146C" }, 55 { "rmd160","726EDD1BB5DB3642", "46A231C501A1D2CE", "848664EF3A300CC9" }, 56 { "sha1","AD85F658EBE383C9", "D07CE229B5CF119B", "27BC71035AAF3DC6" }, 57 { NULL } } }, 58 { "OTP's are good", "correct", { 59 { "md5", "F205753943DE4CF9", "DDCDAC956F234937", "B203E28FA525BE47" }, 60 { "rmd160","F90D03CC969208C8", "B6F5D25A08A90009", "C890C1F05018BA5F" }, 61 { "sha1","D51F3E99BF8E6F0B", "82AEB52D943774E4", "4F296A74FE1567EC" }, 62 { NULL } } }, 63 { NULL } 64 }; 65 66 int 67 main(int argc, char *argv[]) 68 { 69 char data[16], prn[64]; 70 struct regPass *rp; 71 int i = 0; 72 int errors = 0; 73 int j; 74 75 if (strcmp(skey_get_algorithm(), "md5") != 0) { 76 errors++; 77 printf("default algorithm is not md5\n"); 78 } 79 80 if (skey_set_algorithm("md4") != NULL) { 81 errors++; 82 printf("accepted unsupported algorithm md4\n"); 83 } 84 85 for(rp = regPass; rp->passphrase; rp++) { 86 struct regRes *rr; 87 88 i++; 89 for(rr = rp->res; rr->algo; rr++) { 90 if (skey_set_algorithm(rr->algo) == NULL) { 91 errors++; 92 printf("Set %d: %s algorithm is not supported\n", 93 i, rr->algo); 94 continue; 95 } 96 97 if (strcmp(skey_get_algorithm(), rr->algo) != 0) { 98 errors++; 99 printf("Set %d: unable to set algorithm to %s\n", 100 i, rr->algo); 101 continue; 102 } 103 104 keycrunch(data, rp->seed, rp->passphrase); 105 btoa8(prn, data); 106 107 if(strcasecmp(prn, rr->zero)) { 108 errors++; 109 printf("Set %d, round 0, %s: Expected %s and got %s\n", 110 i, rr->algo, rr->zero, prn); 111 } 112 113 f(data); 114 btoa8(prn, data); 115 116 if(strcasecmp(prn, rr->one)) { 117 errors++; 118 printf("Set %d, round 1, %s: Expected %s and got %s\n", 119 i, rr->algo, rr->one, prn); 120 } 121 122 for(j=1; j<99; j++) 123 f(data); 124 btoa8(prn, data); 125 126 if(strcasecmp(prn, rr->nine)) { 127 errors++; 128 printf("Set %d, round 99, %s: Expected %s and got %s\n", 129 i, rr->algo, rr->nine, prn); 130 } 131 } 132 } 133 134 printf("%d errors\n", errors); 135 return(errors ? 1 : 0); 136 } 137