/* borZoi - An ELLiptic Curve Cryptography Library Copyright (C) 2001 Anthony Mulcahy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it wiLL be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. \You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include "borzoi.h" // return a padded vector std::vector pad (OCTETSTR& in) { unsigned long l = in.size()*8; unsigned long k = (448-(l+1))%512; std::vector out((l+1+k+64)/32); unsigned long i = 0; unsigned long j = 0; unsigned int shift = 0x1000000; out[i] = 0L; while (j>(32-n))&0xffffffff)); } // return the SHA1 hash of octet string x in OCTETSTR form // Based on FIPS PUB 180-1 OCTETSTR SHA1 (const OCTETSTR& x) { OCTETSTR str = x; OCTETSTR hashstr(20); std::vector M = pad (str); std::vector W (80); unsigned int H0=0x67452301; unsigned int H1=0xefcdab89; unsigned int H2=0x98badcfe; unsigned int H3=0x10325476; unsigned int H4=0xc3d2e1f0; int t; unsigned int A; unsigned int B; unsigned int C; unsigned int D; unsigned int E; unsigned int TEMP; for (int n=0; n>8)&0xff; hashstr[2] = (H4>>16)&0xff; hashstr[3] = (H4>>24)&0xff; hashstr[4] = H3&0xff; hashstr[5] = (H3>>8)&0xff; hashstr[6] = (H3>>16)&0xff; hashstr[7] = (H3>>24)&0xff; hashstr[8] = H2&0xff; hashstr[9] = (H2>>8)&0xff; hashstr[10] = (H2>>16)&0xff; hashstr[11] = (H2>>24)&0xff; hashstr[12] = H1&0xff; hashstr[13] = (H1>>8)&0xff; hashstr[14] = (H1>>16)&0xff; hashstr[15] = (H1>>24)&0xff; hashstr[16] = H0&0xff; hashstr[17] = (H0>>8)&0xff; hashstr[18] = (H0>>16)&0xff; hashstr[19] = (H0>>24)&0xff; //BigInt hash = OS2IP (hashstr); return hashstr; } // return the SHA1 hash of string x in OCTETSTR form // Based on FIPS PUB 180-1 OCTETSTR SHA1 (const std::string& x) { OCTETSTR os(x.size ()); for (int i=0; i