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.
103 lines
1.7 KiB
103 lines
1.7 KiB
|
|
#include "main.h"
|
|
|
|
#define DEBUG
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define MYUBRR 8 /*BAUD=115200*/
|
|
|
|
void initUSART(){
|
|
UBRR0 = (unsigned char) MYUBRR;
|
|
|
|
/*enable USART write and read*/
|
|
UCSR0B |= /*(1<<RXCIE)|*/(1<<RXEN0)|(1<<TXEN0);
|
|
/*odd parity, 1 stop bit, 8bit words*/
|
|
UCSR0C |= (1<<UPM01)|(1<<UPM00)|(1<<UCSZ01)|(1<<UCSZ00);
|
|
}
|
|
|
|
void tx( char data ){
|
|
while ( !( UCSR0A & (1<<UDRE0)) );
|
|
UDR0 = data;
|
|
}
|
|
|
|
void sendstr( char* str){
|
|
while(str[0]!=0){
|
|
tx(str[0]);
|
|
str++;
|
|
}
|
|
}
|
|
|
|
void sendunum(uint32_t num){
|
|
char text[11] = {0,0,0,0,0,0,0,0,0,0,0};
|
|
uint32_t tmp=1;
|
|
char leadingzero=0;
|
|
char digit=0;
|
|
char i;
|
|
if(num==0){
|
|
tx('0');
|
|
return;
|
|
}
|
|
for(i=1;i<=10;i++){
|
|
digit = '0'+((num/tmp)%10);
|
|
tmp*=10;
|
|
if(digit=='0'){
|
|
leadingzero++;
|
|
}else{
|
|
leadingzero=0;
|
|
}
|
|
text[10-i]=digit;
|
|
}
|
|
sendstr( text+leadingzero );
|
|
}
|
|
|
|
void tx_hex(uint8_t c){
|
|
if( ((c&0xF0)>>4) <0x0A ){
|
|
tx('0'+((c&0xF0)>>4) );
|
|
}else{
|
|
tx('A'-0x0A+((c&0xF0)>>4));
|
|
}
|
|
|
|
if( (c&0x0F)<0x0A ){
|
|
tx('0'+(c&0x0F));
|
|
}else{
|
|
tx('A'-0x0A+(c&0x0F));
|
|
}
|
|
}
|
|
|
|
char rx( void ){
|
|
while ( !(UCSR0A & (1<<RXC0)) );
|
|
return UDR0;
|
|
}
|
|
#endif //DEBUG
|
|
|
|
#define SECRET {'J', 'e', 'f', 'e'};
|
|
#define SECLEN 4
|
|
|
|
#define MSG "what do ya want for nothing?"
|
|
|
|
|
|
int main(void) __attribute__((noreturn));
|
|
int __attribute__((OS_main)) main(void) {
|
|
int8_t i;
|
|
uint8_t sec[SECLEN]=SECRET;
|
|
|
|
initUSART();
|
|
//sendstr("Hello\n");
|
|
|
|
tx('+');
|
|
|
|
hmac(MSG,28,sec,4);
|
|
//get_otp_from_cnt(777, 6, sec, SECLEN); //get a 6 digit one-time-password with counter 777
|
|
for(i=0; i<20; i++){
|
|
tx_hex( ((uint8_t*)sha1_digest)[i] );
|
|
}
|
|
|
|
tx('+');
|
|
tx('\n');
|
|
|
|
for(;;){
|
|
|
|
}
|
|
}
|
|
|
|
|