t_algorithms.c revision 272343
11573Srgrimes/* $NetBSD: t_algorithms.c,v 1.1 2010/07/16 13:56:32 jmmv Exp $ */ 21573Srgrimes 31573Srgrimes/* 41573Srgrimes * Copyright (c) 2000, 2008, 2010 The NetBSD Foundation, Inc. 51573Srgrimes * All rights reserved. 61573Srgrimes * 71573Srgrimes * Redistribution and use in source and binary forms, with or without 81573Srgrimes * modification, are permitted provided that the following conditions 91573Srgrimes * are met: 101573Srgrimes * 1. Redistributions of source code must retain the above copyright 111573Srgrimes * notice, this list of conditions and the following disclaimer. 121573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 131573Srgrimes * notice, this list of conditions and the following disclaimer in the 141573Srgrimes * documentation and/or other materials provided with the distribution. 151573Srgrimes * 161573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 171573Srgrimes * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 181573Srgrimes * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 191573Srgrimes * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 201573Srgrimes * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 211573Srgrimes * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 221573Srgrimes * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 231573Srgrimes * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 241573Srgrimes * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 251573Srgrimes * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 261573Srgrimes * POSSIBILITY OF SUCH DAMAGE. 271573Srgrimes */ 281573Srgrimes 291573Srgrimes#include <sys/cdefs.h> 301573Srgrimes__COPYRIGHT("@(#) Copyright (c) 2008, 2010\ 311573Srgrimes The NetBSD Foundation, inc. All rights reserved."); 321573Srgrimes__RCSID("$NetBSD: t_algorithms.c,v 1.1 2010/07/16 13:56:32 jmmv Exp $"); 331573Srgrimes 341573Srgrimes#include <stdio.h> 351573Srgrimes#include <strings.h> 361573Srgrimes#include <skey.h> 371573Srgrimes 381573Srgrimes#include <atf-c.h> 391573Srgrimes 4092986Sobrien#define H_REQUIRE(x, y) \ 4192986Sobrien ATF_REQUIRE_MSG(strcasecmp((x), (y)) == 0, "\"%s\" != \"%s\"", (x), (y)) 421573Srgrimes 431573Srgrimesstatic void 441573Srgrimesh_check(const char *pass, const char *seed, 451573Srgrimes const char *algo, const char *zero, 461573Srgrimes const char *one, const char *nine) 471573Srgrimes{ 481573Srgrimes char prn[64]; 4971579Sdeischen char data[16]; 501573Srgrimes int i; 511573Srgrimes 5287113Sfenner skey_set_algorithm(algo); 531573Srgrimes 5487490Sphantom keycrunch(data, seed, pass); 5587113Sfenner btoa8(prn, data); 5687113Sfenner H_REQUIRE(prn, zero); 571573Srgrimes 581573Srgrimes f(data); 591573Srgrimes btoa8(prn, data); 60103633Stjr H_REQUIRE(prn, one); 611573Srgrimes 621573Srgrimes for(i = 1; i < 99; ++i) 6371579Sdeischen f(data); 641573Srgrimes btoa8(prn, data); 6571579Sdeischen H_REQUIRE(prn, nine); 661573Srgrimes} 671573Srgrimes 681573SrgrimesATF_TC(md4); 691573SrgrimesATF_TC_HEAD(md4, tc) 701573Srgrimes{ 711573Srgrimes atf_tc_set_md_var(tc, "descr", "Checks MD4 algorithm"); 7284922Sdfr} 7384962SbdeATF_TC_BODY(md4, tc) 7484962Sbde{ 7584962Sbde h_check("This is a test.", "TeSt", "md4", "D1854218EBBB0B51", 7684962Sbde "63473EF01CD0B444", "C5E612776E6C237A"); 7787113Sfenner h_check("AbCdEfGhIjK", "alpha1", "md4", "50076F47EB1ADE4E", 7887113Sfenner "65D20D1949B5F7AB", "D150C82CCE6F62D1"); 7987113Sfenner h_check("OTP's are good", "correct", "md4", "849C79D4F6F55388", 8087113Sfenner "8C0992FB250847B1", "3F3BF4B4145FD74B"); 8187113Sfenner} 8287113Sfenner 8384962SbdeATF_TC(md5); 8484962SbdeATF_TC_HEAD(md5, tc) 8587113Sfenner{ 8684962Sbde atf_tc_set_md_var(tc, "descr", "Checks MD5 algorithm"); 8784962Sbde} 8884962SbdeATF_TC_BODY(md5, tc) 8987113Sfenner{ 9087113Sfenner h_check("This is a test.", "TeSt", "md5", "9E876134D90499DD", 9187113Sfenner "7965E05436F5029F", "50FE1962C4965880"); 9287113Sfenner h_check("AbCdEfGhIjK", "alpha1", "md5", "87066DD9644BF206", 9384922Sdfr "7CD34C1040ADD14B", "5AA37A81F212146C"); 9484962Sbde h_check("OTP's are good", "correct", "md5", "F205753943DE4CF9", 9584962Sbde "DDCDAC956F234937", "B203E28FA525BE47"); 9684922Sdfr} 97103633Stjr 98103633StjrATF_TC(sha1); 9984922SdfrATF_TC_HEAD(sha1, tc) 10084922Sdfr{ 10187113Sfenner atf_tc_set_md_var(tc, "descr", "Checks SHA1 algorithm"); 10287113Sfenner} 10387113SfennerATF_TC_BODY(sha1, tc) 10487113Sfenner{ 10587113Sfenner h_check("This is a test.", "TeSt", "sha1","BB9E6AE1979D8FF4", 10687113Sfenner "63D936639734385B", "87FEC7768B73CCF9"); 10787113Sfenner h_check("AbCdEfGhIjK", "alpha1", "sha1","AD85F658EBE383C9", 10887113Sfenner "D07CE229B5CF119B", "27BC71035AAF3DC6"); 109103633Stjr h_check("OTP's are good", "correct", "sha1","D51F3E99BF8E6F0B", 11087113Sfenner "82AEB52D943774E4", "4F296A74FE1567EC"); 11187113Sfenner} 11292905Sobrien 11392941SobrienATF_TP_ADD_TCS(tp) 114113146Sdas{ 11592941Sobrien 116113146Sdas ATF_TP_ADD_TC(tp, md4); 11792941Sobrien ATF_TP_ADD_TC(tp, md5); 118103633Stjr ATF_TP_ADD_TC(tp, sha1); 11992905Sobrien 12092905Sobrien return atf_no_error(); 12116586Sjraynard} 1221573Srgrimes