You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.0 KiB
70 lines
2.0 KiB
|
|
#include <stdio.h>
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
|
|
#include "sha1.h"
|
|
#include "hmac.h"
|
|
|
|
char sha1sum[41];
|
|
|
|
#define SHA1STR() { \
|
|
p=sha1sum; \
|
|
for(i=19; i>=0; --i){ \
|
|
sprintf(p,"%02x", ((unsigned char*)(sha1_digest))[i] ); \
|
|
p+=2; \
|
|
}}
|
|
|
|
#define SOMEDATA "fassadenpassformpassendedachkonstuktionen_lagerraumroboterverwaltungssoftwarejungelnesehtorptsurb_fahrradpumpenschlauch_mcguiver_mit_pommes"
|
|
|
|
#define SECRET1 {0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b}
|
|
#define MSG1 "Hi There"
|
|
|
|
#define SECRET2 {'J', 'e', 'f', 'e'};
|
|
#define MSG2 "what do ya want for nothing?"
|
|
|
|
int main(){
|
|
/*SHA1STR makro needs those two*/
|
|
int i;
|
|
char* p;
|
|
|
|
sha1_init();
|
|
sha1_fill(0);
|
|
SHA1STR();
|
|
printf("SHA1: %s\n",sha1sum);
|
|
assert(strcmp("da39a3ee5e6b4b0d3255bfef95601890afd80709",sha1sum)==0);
|
|
|
|
sha1_init();
|
|
sha1_addbyte('a');
|
|
sha1_addbyte('b');
|
|
sha1_addbyte('c');
|
|
sha1_fill(3);
|
|
SHA1STR();
|
|
printf("SHA1: %s\n",sha1sum);
|
|
assert(strcmp("a9993e364706816aba3e25717850c26c9cd0d89d",sha1sum)==0);
|
|
|
|
sha1_init();
|
|
for(i=0;i<strlen(SOMEDATA);i++){
|
|
sha1_addbyte(SOMEDATA[i]);
|
|
}
|
|
sha1_fill( strlen(SOMEDATA) );
|
|
SHA1STR();
|
|
printf("SHA1: %s\n",sha1sum);
|
|
assert(strcmp("4d71043a68fa28b9592d1aa5748e5cd4291c0512",sha1sum)==0);
|
|
|
|
char sec1[20]=SECRET1;
|
|
hmac(MSG1,8,sec1,20);
|
|
SHA1STR();
|
|
printf("HMAC: %s\n",sha1sum);
|
|
assert(strcmp("b617318655057264e28bc0b6fb378c8ef146be00",sha1sum)==0);
|
|
|
|
char sec2[4]=SECRET2;
|
|
hmac(MSG2,28,sec2,4);
|
|
SHA1STR();
|
|
printf("HMAC: %s\n",sha1sum);
|
|
assert(strcmp("effcdf6ae5eb2fa2d27416d5f184df9c259a7c79",sha1sum)==0);
|
|
|
|
printf("OTP: %d\n",get_otp_from_cnt(777, 6, sec2, 4));
|
|
|
|
|
|
}
|
|
|