00001 // Copyright (C) 2006-2007 Benedikt Böhm <hollow@gentoo.org> 00002 // 00003 // The Whirlpool algorithm was developed by 00004 // Paulo S. L. M. Barreto <pbarreto@scopus.com.br> and 00005 // Vincent Rijmen <vincent.rijmen@cryptomathic.com> 00006 // 00007 // This program is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 2 00010 // of the License, or (at your option) any later version. 00011 // 00012 // This program is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with this program; if not, write to the Free Software 00019 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00020 00021 #include "mem.h" 00022 #include "str.h" 00023 #include "stralloc.h" 00024 #include "whirlpool.h" 00025 00026 char *whirlpool_digest(const char *str) 00027 { 00028 whirlpool_t ctx; 00029 stralloc_t sa; 00030 char *buf; 00031 uint8_t digest[DIGESTBYTES]; 00032 int i; 00033 00034 whirlpool_init(&ctx); 00035 whirlpool_add(&ctx, (const unsigned char * const) str, str_len(str)*8); 00036 whirlpool_finalize(&ctx, digest); 00037 00038 stralloc_init(&sa); 00039 00040 for (i = 0; i < DIGESTBYTES; i++) 00041 stralloc_catf(&sa, "%02X", digest[i]); 00042 00043 buf = stralloc_finalize(&sa); 00044 00045 stralloc_free(&sa); 00046 00047 return buf; 00048 }