X-Git-Url: http://www.average.org/gitweb/?p=pam_pcsc_cr.git;a=blobdiff_plain;f=test_crypto.c;h=f9099a278698c6fb7d5dccaf857c59c671e01850;hp=fe762cf62158720a886394f74942705bd2acf80b;hb=2b714d273b08b945ef677e0fbbf2c8d3d4437980;hpb=8c8a47cd542e60381773fe23f2075aa5b896be4f diff --git a/test_crypto.c b/test_crypto.c index fe762cf..f9099a2 100644 --- a/test_crypto.c +++ b/test_crypto.c @@ -1,3 +1,26 @@ +/* +Copyright (c) 2013 Eugene Crosser + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must + not claim that you wrote the original software. If you use this + software in a product, an acknowledgment in the product documentation + would be appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must + not be misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ + #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -29,13 +52,15 @@ int test_enc_dec(int iface1, int iface2) printh(pt); printh(key); if (select_crypto_if(iface1)) return 1; + memset(ct, 0xfe, sizeof(ct)); if ((err = encrypt(key, sizeof(key), pt, ct, sizeof(pt)))) { printf("encrypt error: %s\n", crypto_errstr(err)); return 1; } printh(ct); if (select_crypto_if(iface2)) return 1; - if ((err = decrypt(key, sizeof(key), ct, re, sizeof(ct)))) { + memset(re, 0xab, sizeof(re)); + if ((err = decrypt(key, sizeof(key), ct, re, sizeof(re)))) { printf("decrypt error: %s\n", crypto_errstr(err)); return 1; } @@ -57,7 +82,8 @@ int test_sha(int iface) 0xBA,0x3E,0x25,0x71,0x78,0x50,0xC2,0x6C,0x9C,0xD0,0xD8,0x9D}; if (select_crypto_if(iface)) return 1; - shalen = 20; + memset(sha1, 0, sizeof(sha1)); + shalen = sizeof(sha1); if ((err = hash(spt, sizeof(spt), sha1, &shalen))) { printf("hash error: %s\n", crypto_errstr(err)); return 1; @@ -82,7 +108,8 @@ int test_hmac(int iface) 0xd2,0x74,0x16,0xd5,0xf1,0x84,0xdf,0x9c,0x25,0x9a,0x7c,0x79}; if (select_crypto_if(iface)) return 1; - hmaclen = 20; + memset(hmac1, 0, sizeof(hmac1)); + hmaclen = sizeof(hmac1); if ((err = hmac(hkey, sizeof(hkey), hpt, sizeof(hpt), hmac1, &hmaclen))) { printf("hash error: %s\n", crypto_errstr(err)); @@ -101,10 +128,11 @@ int main(int argc, char *argv[]) { int rc, maxrc = 0; int numifs, i, j; + const char *name; - for (numifs = 0; select_crypto_if(numifs) == 0; numifs++) - printf("%d: %s\n", numifs, if_name(numifs)); - printf("Testing %d interfaces\n", numifs); + for (numifs = 0; (name = crypto_init(numifs)); numifs++) + printf("%d: %s\n", numifs, name); + printf("Testing %d interfaces\n\n", numifs); for (i = 0; i < numifs; i++) if ((rc = test_sha(i)) > maxrc) maxrc = rc;