155682Smarkm/* 2233294Sstas * Copyright (c) 1999 - 2001 Kungliga Tekniska H��gskolan 3233294Sstas * (Royal Institute of Technology, Stockholm, Sweden). 4233294Sstas * All rights reserved. 555682Smarkm * 6233294Sstas * Redistribution and use in source and binary forms, with or without 7233294Sstas * modification, are permitted provided that the following conditions 8233294Sstas * are met: 955682Smarkm * 10233294Sstas * 1. Redistributions of source code must retain the above copyright 11233294Sstas * notice, this list of conditions and the following disclaimer. 1255682Smarkm * 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. 1655682Smarkm * 1755682Smarkm * 3. Neither the name of KTH nor the names of its contributors may be 1855682Smarkm * used to endorse or promote products derived from this software without 1955682Smarkm * specific prior written permission. 2055682Smarkm * 2155682Smarkm * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY 2255682Smarkm * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2355682Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2455682Smarkm * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE 2555682Smarkm * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2655682Smarkm * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2755682Smarkm * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 2855682Smarkm * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2955682Smarkm * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 3055682Smarkm * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 3155682Smarkm * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 3255682Smarkm 3355682Smarkm#include "krb5_locl.h" 3455682Smarkm 3555682Smarkmenum { MAXSIZE = 24 }; 3655682Smarkm 3755682Smarkmstatic struct testcase { 3855682Smarkm const char *str; 3955682Smarkm unsigned n; 4055682Smarkm unsigned char res[MAXSIZE]; 4155682Smarkm} tests[] = { 4255682Smarkm {"012345", 8, 4355682Smarkm {0xbe, 0x07, 0x26, 0x31, 0x27, 0x6b, 0x19, 0x55} 4455682Smarkm }, 4555682Smarkm {"basch", 24, 4655682Smarkm {0x1a, 0xab, 0x6b, 0x42, 0x96, 0x4b, 0x98, 0xb2, 0x1f, 0x8c, 0xde, 4755682Smarkm 0x2d, 0x24, 0x48, 0xba, 0x34, 0x55, 0xd7, 0x86, 0x2c, 0x97, 0x31, 4855682Smarkm 0x64, 0x3f} 4955682Smarkm }, 5055682Smarkm {"eichin", 24, 5155682Smarkm {0x65, 0x69, 0x63, 0x68, 0x69, 0x6e, 0x4b, 0x73, 0x2b, 0x4b, 5255682Smarkm 0x1b, 0x43, 0xda, 0x1a, 0x5b, 0x99, 0x5a, 0x58, 0xd2, 0xc6, 0xd0, 5355682Smarkm 0xd2, 0xdc, 0xca} 5455682Smarkm }, 5555682Smarkm {"sommerfeld", 24, 5655682Smarkm {0x2f, 0x7a, 0x98, 0x55, 0x7c, 0x6e, 0xe4, 0xab, 0xad, 0xf4, 5755682Smarkm 0xe7, 0x11, 0x92, 0xdd, 0x44, 0x2b, 0xd4, 0xff, 0x53, 0x25, 0xa5, 5855682Smarkm 0xde, 0xf7, 0x5c} 5955682Smarkm }, 6055682Smarkm {"MASSACHVSETTS INSTITVTE OF TECHNOLOGY", 24, 6155682Smarkm {0xdb, 0x3b, 0x0d, 0x8f, 0x0b, 0x06, 0x1e, 0x60, 0x32, 0x82, 6255682Smarkm 0xb3, 0x08, 0xa5, 0x08, 0x41, 0x22, 0x9a, 0xd7, 0x98, 0xfa, 0xb9, 6355682Smarkm 0x54, 0x0c, 0x1b} 6455682Smarkm }, 6555682Smarkm {"assar@NADA.KTH.SE", 24, 6655682Smarkm {0x5c, 0x06, 0xc3, 0x4d, 0x2c, 0x89, 0x05, 0xbe, 0x7a, 0x51, 6755682Smarkm 0x83, 0x6c, 0xd6, 0xf8, 0x1c, 0x4b, 0x7a, 0x93, 0x49, 0x16, 0x5a, 6855682Smarkm 0xb3, 0xfa, 0xa9} 6955682Smarkm }, 7055682Smarkm {"testKRBTEST.MIT.EDUtestkey", 24, 7155682Smarkm {0x50, 0x2c, 0xf8, 0x29, 0x78, 0xe5, 0xfb, 0x1a, 0x29, 0x06, 7255682Smarkm 0xbd, 0x22, 0x28, 0x91, 0x56, 0xc0, 0x06, 0xa0, 0xdc, 0xf5, 0xb6, 7355682Smarkm 0xc2, 0xda, 0x6c} 7455682Smarkm }, 7578527Sassar {"password", 7, 7678527Sassar {0x78, 0xa0, 0x7b, 0x6c, 0xaf, 0x85, 0xfa} 7778527Sassar }, 7878527Sassar {"Rough Consensus, and Running Code", 8, 7978527Sassar {0xbb, 0x6e, 0xd3, 0x08, 0x70, 0xb7, 0xf0, 0xe0}, 8078527Sassar }, 8178527Sassar {"password", 21, 8278527Sassar {0x59, 0xe4, 0xa8, 0xca, 0x7c, 0x03, 0x85, 0xc3, 0xc3, 0x7b, 0x3f, 8378527Sassar 0x6d, 0x20, 0x00, 0x24, 0x7c, 0xb6, 0xe6, 0xbd, 0x5b, 0x3e}, 8478527Sassar }, 8578527Sassar {"MASSACHVSETTS INSTITVTE OF TECHNOLOGY", 24, 8678527Sassar {0xdb, 0x3b, 0x0d, 0x8f, 0x0b, 0x06, 0x1e, 0x60, 0x32, 0x82, 0xb3, 8778527Sassar 0x08, 0xa5, 0x08, 0x41, 0x22, 0x9a, 0xd7, 0x98, 0xfa, 0xb9, 0x54, 8878527Sassar 0x0c, 0x1b} 8978527Sassar }, 9055682Smarkm {NULL, 0} 9155682Smarkm}; 9255682Smarkm 9355682Smarkmint 9455682Smarkmmain(int argc, char **argv) 9555682Smarkm{ 9655682Smarkm unsigned char data[MAXSIZE]; 9755682Smarkm struct testcase *t; 9855682Smarkm int ret = 0; 9955682Smarkm 10055682Smarkm for (t = tests; t->str; ++t) { 10155682Smarkm int i; 10255682Smarkm 103178825Sdfr ret = _krb5_n_fold (t->str, strlen(t->str), data, t->n); 104178825Sdfr if (ret) 105178825Sdfr errx(1, "out of memory"); 10655682Smarkm if (memcmp (data, t->res, t->n) != 0) { 10755682Smarkm printf ("n-fold(\"%s\", %d) failed\n", t->str, t->n); 10855682Smarkm printf ("should be: "); 10955682Smarkm for (i = 0; i < t->n; ++i) 11055682Smarkm printf ("%02x", t->res[i]); 11155682Smarkm printf ("\nresult was: "); 11255682Smarkm for (i = 0; i < t->n; ++i) 11355682Smarkm printf ("%02x", data[i]); 11455682Smarkm printf ("\n"); 11555682Smarkm ret = 1; 11655682Smarkm } 11755682Smarkm } 11855682Smarkm return ret; 11955682Smarkm} 120