1 /* $OpenBSD: skeytest.c,v 1.3 2008/06/26 05:42:05 ray 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 /* This is a regression test for the S/Key implementation 31 against the data set from Appendix C of RFC2289 */ 32 33 #include <stdio.h> 34 #include <string.h> 35 #include "skey.h" 36 37 struct regRes { 38 char *algo, *zero, *one, *nine; 39 }; 40 41 struct regPass { 42 char *passphrase, *seed; 43 struct regRes res[4]; 44 } regPass[] = { 45 { "This is a test.", "TeSt", { 46 { "md4", "D1854218EBBB0B51", "63473EF01CD0B444", "C5E612776E6C237A" }, 47 { "md5", "9E876134D90499DD", "7965E05436F5029F", "50FE1962C4965880" }, 48 { "sha1","BB9E6AE1979D8FF4", "63D936639734385B", "87FEC7768B73CCF9" }, 49 { NULL } } }, 50 { "AbCdEfGhIjK", "alpha1", { 51 { "md4", "50076F47EB1ADE4E", "65D20D1949B5F7AB", "D150C82CCE6F62D1" }, 52 { "md5", "87066DD9644BF206", "7CD34C1040ADD14B", "5AA37A81F212146C" }, 53 { "sha1","AD85F658EBE383C9", "D07CE229B5CF119B", "27BC71035AAF3DC6" }, 54 { NULL } } }, 55 { "OTP's are good", "correct", { 56 { "md4", "849C79D4F6F55388", "8C0992FB250847B1", "3F3BF4B4145FD74B" }, 57 { "md5", "F205753943DE4CF9", "DDCDAC956F234937", "B203E28FA525BE47" }, 58 { "sha1","D51F3E99BF8E6F0B", "82AEB52D943774E4", "4F296A74FE1567EC" }, 59 { NULL } } }, 60 { NULL } 61 }; 62 63 int 64 main(int argc, char *argv[]) 65 { 66 char data[16], prn[64]; 67 struct regPass *rp; 68 int i = 0; 69 int errors = 0; 70 int j; 71 72 for(rp = regPass; rp->passphrase; rp++) { 73 struct regRes *rr; 74 75 i++; 76 for(rr = rp->res; rr->algo; rr++) { 77 skey_set_algorithm(rr->algo); 78 79 keycrunch(data, rp->seed, rp->passphrase); 80 btoa8(prn, data); 81 82 if(strcasecmp(prn, rr->zero)) { 83 errors++; 84 printf("Set %d, round 0, %s: Expected %s and got %s\n", 85 i, rr->algo, rr->zero, prn); 86 } 87 88 f(data); 89 btoa8(prn, data); 90 91 if(strcasecmp(prn, rr->one)) { 92 errors++; 93 printf("Set %d, round 1, %s: Expected %s and got %s\n", 94 i, rr->algo, rr->one, prn); 95 } 96 97 for(j=1; j<99; j++) 98 f(data); 99 btoa8(prn, data); 100 101 if(strcasecmp(prn, rr->nine)) { 102 errors++; 103 printf("Set %d, round 99, %s: Expected %s and got %s\n", 104 i, rr->algo, rr->nine, prn); 105 } 106 } 107 } 108 109 printf("%d errors\n", errors); 110 return(errors ? 1 : 0); 111 } 112