modified structure
This commit is contained in:
parent
8f855d283a
commit
d32eba56ce
|
@ -0,0 +1,246 @@
|
|||
/* base64_dec.c */
|
||||
/*
|
||||
* This file is part of the AVR-Crypto-Lib.
|
||||
* Copyright (C) 2006, 2007, 2008 Daniel Otte (daniel.otte@rub.de)
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* base64 decoder (RFC3548)
|
||||
* Author: Daniel Otte
|
||||
* License: GPLv3
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "base64_dec.h"
|
||||
|
||||
#include "test_src/cli.h"
|
||||
|
||||
/*
|
||||
#define USE_GCC_EXTENSION
|
||||
*/
|
||||
#if 1
|
||||
|
||||
#ifdef USE_GCC_EXTENSION
|
||||
|
||||
static
|
||||
int ascii2bit6(char a){
|
||||
switch(a){
|
||||
case 'A'...'Z':
|
||||
return a-'A';
|
||||
case 'a'...'z':
|
||||
return a-'a'+26;
|
||||
case '0'...'9':
|
||||
return a-'0'+52;
|
||||
case '+':
|
||||
case '-':
|
||||
return 62;
|
||||
case '/':
|
||||
case '_':
|
||||
return 63;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static
|
||||
uint8_t ascii2bit6(char a){
|
||||
int r;
|
||||
switch(a>>4){
|
||||
case 0x5:
|
||||
case 0x4:
|
||||
r=a-'A';
|
||||
if(r<0 || r>25){
|
||||
return -1;
|
||||
} else {
|
||||
return r;
|
||||
}
|
||||
case 0x7:
|
||||
case 0x6:
|
||||
r=a-'a';
|
||||
if(r<0 || r>25){
|
||||
return -1;
|
||||
} else {
|
||||
return r+26;
|
||||
}
|
||||
break;
|
||||
case 0x3:
|
||||
if(a>'9')
|
||||
return -1;
|
||||
return a-'0'+52;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (a){
|
||||
case '+':
|
||||
case '-':
|
||||
return 62;
|
||||
case '/':
|
||||
case '_':
|
||||
return 63;
|
||||
default:
|
||||
return 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
static
|
||||
uint8_t ascii2bit6(uint8_t a){
|
||||
if(a>='A' && a<='Z'){
|
||||
return a-'A';
|
||||
} else {
|
||||
if(a>='a' && a<= 'z'){
|
||||
return a-'a'+26;
|
||||
} else {
|
||||
if(a>='0' && a<='9'){
|
||||
return a-'0'+52;
|
||||
} else {
|
||||
if(a=='+' || a=='-'){
|
||||
return 62;
|
||||
} else {
|
||||
if(a=='/' || a=='_'){
|
||||
return 63;
|
||||
} else {
|
||||
return 0xff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int base64_binlength(char* str, uint8_t strict){
|
||||
int l=0;
|
||||
uint8_t term=0;
|
||||
for(;;){
|
||||
if(*str=='\0')
|
||||
break;
|
||||
if(*str=='\n' || *str=='\r'){
|
||||
str++;
|
||||
continue;
|
||||
}
|
||||
if(*str=='='){
|
||||
term++;
|
||||
str++;
|
||||
if(term==2){
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(term)
|
||||
return -1;
|
||||
if(ascii2bit6(*str)==-1){
|
||||
if(strict)
|
||||
return -1;
|
||||
} else {
|
||||
l++;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
switch(term){
|
||||
case 0:
|
||||
if(l%4!=0)
|
||||
return -1;
|
||||
return l/4*3;
|
||||
case 1:
|
||||
if(l%4!=3)
|
||||
return -1;
|
||||
return (l+1)/4*3-1;
|
||||
case 2:
|
||||
if(l%4!=2)
|
||||
return -1;
|
||||
return (l+2)/4*3-2;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|543210543210543210543210|
|
||||
|765432107654321076543210|
|
||||
|
||||
. . . .
|
||||
|54321054|32105432|10543210|
|
||||
|76543210|76543210|76543210|
|
||||
|
||||
*/
|
||||
|
||||
int base64dec(void* dest, char* b64str, uint8_t strict){
|
||||
uint8_t buffer[4];
|
||||
uint8_t idx=0;
|
||||
uint8_t term=0;
|
||||
for(;;){
|
||||
// cli_putstr_P(PSTR("\r\n DBG: got 0x"));
|
||||
// cli_hexdump(b64str, 1);
|
||||
buffer[idx]= ascii2bit6(*b64str);
|
||||
// cli_putstr_P(PSTR(" --> 0x"));
|
||||
// cli_hexdump(buffer+idx, 1);
|
||||
|
||||
if(buffer[idx]==0xFF){
|
||||
if(*b64str=='='){
|
||||
term++;
|
||||
b64str++;
|
||||
if(term==2)
|
||||
goto finalize; /* definitly the end */
|
||||
}else{
|
||||
if(*b64str == '\0'){
|
||||
goto finalize; /* definitly the end */
|
||||
}else{
|
||||
if(*b64str == '\r' || *b64str == '\n' || !(strict)){
|
||||
b64str++; /* charcters that we simply ignore */
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(term)
|
||||
return -1; /* this happens if we get a '=' in the stream */
|
||||
idx++;
|
||||
b64str++;
|
||||
}
|
||||
if(idx==4){
|
||||
((uint8_t*)dest)[0] = buffer[0]<<2 | buffer[1]>>4;
|
||||
((uint8_t*)dest)[1] = buffer[1]<<4 | buffer[2]>>2;
|
||||
((uint8_t*)dest)[2] = buffer[2]<<6 | buffer[3];
|
||||
dest = (uint8_t*)dest +3;
|
||||
idx=0;
|
||||
}
|
||||
}
|
||||
finalize:
|
||||
/* the final touch */
|
||||
if(idx==0)
|
||||
return 0;
|
||||
if(term==1){
|
||||
((uint8_t*)dest)[0] = buffer[0]<<2 | buffer[1]>>4;
|
||||
((uint8_t*)dest)[1] = buffer[1]<<4 | buffer[2]>>2;
|
||||
return 0;
|
||||
}
|
||||
if(term==2){
|
||||
((uint8_t*)dest)[0] = buffer[0]<<2 | buffer[1]>>4;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/* base64_dec.h */
|
||||
/*
|
||||
* This file is part of the AVR-Crypto-Lib.
|
||||
* Copyright (C) 2006, 2007, 2008 Daniel Otte (daniel.otte@rub.de)
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef BASE64_DEC_H_
|
||||
#define BASE64_DEC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int base64_binlength(char* str, uint8_t strict);
|
||||
int base64dec(void* dest, char* b64str, uint8_t strict);
|
||||
|
||||
#endif /*BASE64_DEC_H_*/
|
|
@ -0,0 +1,117 @@
|
|||
/* base64_enc.c */
|
||||
/*
|
||||
* This file is part of the AVR-Crypto-Lib.
|
||||
* Copyright (C) 2006, 2007, 2008 Daniel Otte (daniel.otte@rub.de)
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* base64 encoder (RFC3548)
|
||||
* Author: Daniel Otte
|
||||
* License: GPLv3
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "base64_enc.h"
|
||||
|
||||
#if 1
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
char base64_alphabet[64] PROGMEM = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3',
|
||||
'4', '5', '6', '7', '8', '9', '+', '/' };
|
||||
|
||||
static
|
||||
char bit6toAscii(uint8_t a){
|
||||
a &= (uint8_t)0x3F;
|
||||
return pgm_read_byte(base64_alphabet+a);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static
|
||||
char bit6toAscii(uint8_t a){
|
||||
a &= (uint8_t)0x3F;
|
||||
|
||||
if(a<=25){
|
||||
return a+'A';
|
||||
} else {
|
||||
if(a<=51){
|
||||
return a-26+'a';
|
||||
} else {
|
||||
if(a<=61){
|
||||
return a-52+'0';
|
||||
} else {
|
||||
if(a==62){
|
||||
return '+';
|
||||
} else {
|
||||
return '/'; /* a == 63 */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void base64enc(char* dest, void* src, uint16_t length){
|
||||
uint16_t i,j;
|
||||
uint8_t a[4];
|
||||
for(i=0; i<length/3; ++i){
|
||||
a[0]= (((uint8_t*)src)[i*3+0])>>2;
|
||||
a[1]= (((((uint8_t*)src)[i*3+0])<<4) | ((((uint8_t*)src)[i*3+1])>>4)) & 0x3F;
|
||||
a[2]= (((((uint8_t*)src)[i*3+1])<<2) | ((((uint8_t*)src)[i*3+2])>>6)) & 0x3F;
|
||||
a[3]= (((uint8_t*)src)[i*3+2]) & 0x3F;
|
||||
for(j=0; j<4; ++j){
|
||||
*dest++=bit6toAscii(a[j]);
|
||||
}
|
||||
}
|
||||
/* now we do the rest */
|
||||
switch(length%3){
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
a[0]=(((uint8_t*)src)[i*3+0])>>2;
|
||||
a[1]=((((uint8_t*)src)[i*3+0])<<4)&0x3F;
|
||||
*dest++ = bit6toAscii(a[0]);
|
||||
*dest++ = bit6toAscii(a[1]);
|
||||
*dest++ = '=';
|
||||
*dest++ = '=';
|
||||
break;
|
||||
case 2:
|
||||
a[0]= (((uint8_t*)src)[i*3+0])>>2;
|
||||
a[1]= (((((uint8_t*)src)[i*3+0])<<4) | ((((uint8_t*)src)[i*3+1])>>4)) & 0x3F;
|
||||
a[2]= ((((uint8_t*)src)[i*3+1])<<2) & 0x3F;
|
||||
*dest++ = bit6toAscii(a[0]);
|
||||
*dest++ = bit6toAscii(a[1]);
|
||||
*dest++ = bit6toAscii(a[2]);
|
||||
*dest++ = '=';
|
||||
break;
|
||||
default: /* this will not happen! */
|
||||
break;
|
||||
}
|
||||
/* finalize: */
|
||||
*dest='\0';
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/* base64_enc.h */
|
||||
/*
|
||||
* This file is part of the AVR-Crypto-Lib.
|
||||
* Copyright (C) 2006, 2007, 2008 Daniel Otte (daniel.otte@rub.de)
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef BASE64_ENC_H_
|
||||
#define BASE64_ENC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void base64enc(char* dest, void* src, uint16_t length);
|
||||
|
||||
#endif /*BASE64_ENC_H_*/
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,122 @@
|
|||
/* sha256.h */
|
||||
/*
|
||||
This file is part of the AVR-Crypto-Lib.
|
||||
Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
|
||||
|
||||
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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* \file sha256.h
|
||||
* \author Daniel Otte
|
||||
* \date 2006-05-16
|
||||
* \license GPLv3 or later
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SHA256_H_
|
||||
#define SHA256_H_
|
||||
|
||||
#define __LITTLE_ENDIAN__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/** \def SHA256_HASH_BITS
|
||||
* defines the size of a SHA-256 hash value in bits
|
||||
*/
|
||||
|
||||
/** \def SHA256_HASH_BYTES
|
||||
* defines the size of a SHA-256 hash value in bytes
|
||||
*/
|
||||
|
||||
/** \def SHA256_BLOCK_BITS
|
||||
* defines the size of a SHA-256 input block in bits
|
||||
*/
|
||||
|
||||
/** \def SHA256_BLOCK_BYTES
|
||||
* defines the size of a SHA-256 input block in bytes
|
||||
*/
|
||||
|
||||
#define SHA256_HASH_BITS 256
|
||||
#define SHA256_HASH_BYTES (SHA256_HASH_BITS/8)
|
||||
#define SHA256_BLOCK_BITS 512
|
||||
#define SHA256_BLOCK_BYTES (SHA256_BLOCK_BITS/8)
|
||||
|
||||
/** \typedef sha256_ctx_t
|
||||
* \brief SHA-256 context type
|
||||
*
|
||||
* A variable of this type may hold the state of a SHA-256 hashing process
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t h[8];
|
||||
uint64_t length;
|
||||
} sha256_ctx_t;
|
||||
|
||||
/** \typedef sha256_hash_t
|
||||
* \brief SHA-256 hash value type
|
||||
*
|
||||
* A variable of this type may hold the hash value produced by the
|
||||
* sha256_ctx2hash(sha256_hash_t* dest, const sha256_ctx_t* state) function.
|
||||
*/
|
||||
typedef uint8_t sha256_hash_t[SHA256_HASH_BYTES];
|
||||
|
||||
/** \fn void sha256_init(sha256_ctx_t *state)
|
||||
* \brief initialise a SHA-256 context
|
||||
*
|
||||
* This function sets a ::sha256_ctx_t to the initial values for hashing.
|
||||
* \param state pointer to the SHA-256 hashing context
|
||||
*/
|
||||
void sha256_init(sha256_ctx_t *state);
|
||||
|
||||
/** \fn void sha256_nextBlock (sha256_ctx_t* state, const void* block)
|
||||
* \brief update the context with a given block
|
||||
*
|
||||
* This function updates the SHA-256 hash context by processing the given block
|
||||
* of fixed length.
|
||||
* \param state pointer to the SHA-256 hash context
|
||||
* \param block pointer to the block of fixed length (512 bit = 64 byte)
|
||||
*/
|
||||
void sha256_nextBlock (sha256_ctx_t* state, const void* block);
|
||||
|
||||
/** \fn void sha256_lastBlock(sha256_ctx_t* state, const void* block, uint16_t length_b)
|
||||
* \brief finalize the context with the given block
|
||||
*
|
||||
* This function finalizes the SHA-256 hash context by processing the given block
|
||||
* of variable length.
|
||||
* \param state pointer to the SHA-256 hash context
|
||||
* \param block pointer to the block of fixed length (512 bit = 64 byte)
|
||||
* \param length_b the length of the block in bits
|
||||
*/
|
||||
void sha256_lastBlock(sha256_ctx_t* state, const void* block, uint16_t length_b);
|
||||
|
||||
/** \fn void sha256_ctx2hash(sha256_hash_t* dest, const sha256_ctx_t* state)
|
||||
* \brief convert the hash state into the hash value
|
||||
* This function reads the context and writes the hash value to the destination
|
||||
* \param dest pointer to the location where the hash value should be written
|
||||
* \param state pointer to the SHA-256 hash context
|
||||
*/
|
||||
void sha256_ctx2hash(sha256_hash_t* dest, const sha256_ctx_t* state);
|
||||
|
||||
/** \fn void sha256(sha256_hash_t* dest, const void* msg, uint32_t length_b)
|
||||
* \brief simple SHA-256 hashing function for direct hashing
|
||||
*
|
||||
* This function automaticaly hashes a given message of arbitary length with
|
||||
* the SHA-256 hashing algorithm.
|
||||
* \param dest pointer to the location where the hash value is going to be written to
|
||||
* \param msg pointer to the message thats going to be hashed
|
||||
* \param length_b length of the message in bits
|
||||
*/
|
||||
void sha256(sha256_hash_t* dest, const void* msg, uint32_t length_b);
|
||||
|
||||
#endif /*SHA256_H_*/
|
|
@ -0,0 +1,977 @@
|
|||
/* md5-asm.S */
|
||||
/*
|
||||
This file is part of the AVR-Crypto-Lib.
|
||||
Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
|
||||
|
||||
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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*
|
||||
* Author: Daniel Otte
|
||||
* License: GPLv3 or later
|
||||
* Date: 2008-11-15
|
||||
*/
|
||||
|
||||
|
||||
#include "avr-asm-macros.S"
|
||||
|
||||
;###########################################################
|
||||
; S-BOX
|
||||
|
||||
T_table:
|
||||
.hword 0xa478, 0xd76a, 0xb756, 0xe8c7, 0x70db, 0x2420, 0xceee, 0xc1bd, 0x0faf, 0xf57c
|
||||
.hword 0xc62a, 0x4787, 0x4613, 0xa830, 0x9501, 0xfd46, 0x98d8, 0x6980, 0xf7af, 0x8b44
|
||||
.hword 0x5bb1, 0xffff, 0xd7be, 0x895c, 0x1122, 0x6b90, 0x7193, 0xfd98, 0x438e, 0xa679
|
||||
.hword 0x0821, 0x49b4, 0x2562, 0xf61e, 0xb340, 0xc040, 0x5a51, 0x265e, 0xc7aa, 0xe9b6
|
||||
.hword 0x105d, 0xd62f, 0x1453, 0x0244, 0xe681, 0xd8a1, 0xfbc8, 0xe7d3, 0xcde6, 0x21e1
|
||||
.hword 0x07d6, 0xc337, 0x0d87, 0xf4d5, 0x14ed, 0x455a, 0xe905, 0xa9e3, 0xa3f8, 0xfcef
|
||||
.hword 0x02d9, 0x676f, 0x4c8a, 0x8d2a, 0x3942, 0xfffa, 0xf681, 0x8771, 0x6122, 0x6d9d
|
||||
.hword 0x380c, 0xfde5, 0xea44, 0xa4be, 0xcfa9, 0x4bde, 0x4b60, 0xf6bb, 0xbc70, 0xbebf
|
||||
.hword 0x7ec6, 0x289b, 0x27fa, 0xeaa1, 0x3085, 0xd4ef, 0x1d05, 0x0488, 0xd039, 0xd9d4
|
||||
.hword 0x99e5, 0xe6db, 0x7cf8, 0x1fa2, 0x5665, 0xc4ac, 0x2244, 0xf429, 0xff97, 0x432a
|
||||
.hword 0x23a7, 0xab94, 0xa039, 0xfc93, 0x59c3, 0x655b, 0xcc92, 0x8f0c, 0xf47d, 0xffef
|
||||
.hword 0x5dd1, 0x8584, 0x7e4f, 0x6fa8, 0xe6e0, 0xfe2c, 0x4314, 0xa301, 0x11a1, 0x4e08
|
||||
.hword 0x7e82, 0xf753, 0xf235, 0xbd3a, 0xd2bb, 0x2ad7, 0xd391, 0xeb86
|
||||
|
||||
|
||||
#define MD5_init_fast
|
||||
|
||||
.global md5_init
|
||||
#ifndef MD5_init_fast
|
||||
;###########################################################
|
||||
;void md5_init(md5_ctx_t *state)
|
||||
; param1: (r24,r25) 16-bit pointer to sha256_ctx_t struct in ram
|
||||
; modifys: Z(r30,r31), X(r25,r26)
|
||||
; size = 9+5*4 WORDS = 29 WORDS = 58 Bytes
|
||||
md5_init:
|
||||
movw r26, r24 ; (24,25) --> (26,27) load X with param1
|
||||
ldi r30, lo8(md5_init_vector)
|
||||
ldi r31, hi8(md5_init_vector)
|
||||
ldi r24, 16+4
|
||||
md5_init_vloop:
|
||||
lpm r0, Z+
|
||||
st X+, r0
|
||||
dec r24
|
||||
brne md5_init_vloop
|
||||
ret
|
||||
|
||||
md5_init_vector:
|
||||
.hword 0x2301, 0x6745
|
||||
.hword 0xAB89, 0xEFCD
|
||||
.hword 0xDCFE, 0x98BA
|
||||
.hword 0x5476, 0x1032
|
||||
.hword 0x0000, 0x0000
|
||||
|
||||
#else
|
||||
;###########################################################
|
||||
.global md5_init_fast
|
||||
;void md5_init(md5_ctx_t *state)
|
||||
; param1: (r24,r25) 16-bit pointer to sha256_ctx_t struct in ram
|
||||
; modifys: r23, r22
|
||||
; cycles = 1+16*3+4*2+4 = 1+48+12 = 61
|
||||
; size = 1+16*2+4+1 WORDS = 38 WORDS = 76 Bytes
|
||||
md5_init:
|
||||
md5_init_fast:
|
||||
movw r26, r24
|
||||
ldi r24, 0x01
|
||||
st X+, r24
|
||||
ldi r24, 0x23
|
||||
st X+, r24
|
||||
ldi r24, 0x45
|
||||
st X+, r24
|
||||
ldi r24, 0x67
|
||||
st X+, r24
|
||||
ldi r24, 0x89
|
||||
st X+, r24
|
||||
ldi r24, 0xAB
|
||||
st X+, r24
|
||||
ldi r24, 0xCD
|
||||
st X+, r24
|
||||
ldi r24, 0xEF
|
||||
st X+, r24
|
||||
ldi r24, 0xFE
|
||||
st X+, r24
|
||||
ldi r24, 0xDC
|
||||
st X+, r24
|
||||
ldi r24, 0xBA
|
||||
st X+, r24
|
||||
ldi r24, 0x98
|
||||
st X+, r24
|
||||
ldi r24, 0x76
|
||||
st X+, r24
|
||||
ldi r24, 0x54
|
||||
st X+, r24
|
||||
ldi r24, 0x32
|
||||
st X+, r24
|
||||
ldi r24, 0x10
|
||||
st X+, r24
|
||||
st X+, r1
|
||||
st X+, r1
|
||||
st X+, r1
|
||||
st X+, r1
|
||||
ret
|
||||
#endif
|
||||
;###########################################################
|
||||
|
||||
/*
|
||||
static
|
||||
uint32_t md5_F(uint32_t x, uint32_t y, uint32_t z){
|
||||
return ((x&y)|((~x)&z));
|
||||
}
|
||||
*/
|
||||
; x: r22-r25
|
||||
; y: r18-r21
|
||||
; z: r14-r17
|
||||
md5_F:
|
||||
and r18, r22
|
||||
and r19, r23
|
||||
and r20, r24
|
||||
and r21, r25
|
||||
com r22
|
||||
com r23
|
||||
com r24
|
||||
com r25
|
||||
and r22, r14
|
||||
and r23, r15
|
||||
and r24, r16
|
||||
and r25, r17
|
||||
or r22, r18
|
||||
or r23, r19
|
||||
or r24, r20
|
||||
or r25, r21
|
||||
rjmp md5_core_F_exit
|
||||
|
||||
/*
|
||||
static
|
||||
uint32_t md5_G(uint32_t x, uint32_t y, uint32_t z){
|
||||
return ((x&z)|((~z)&y));
|
||||
}
|
||||
*/
|
||||
|
||||
; x: r22-r25
|
||||
; y: r18-r21
|
||||
; z: r14-r17
|
||||
md5_G:
|
||||
and r22, r14
|
||||
and r23, r15
|
||||
and r24, r16
|
||||
and r25, r17
|
||||
com r14
|
||||
com r15
|
||||
com r16
|
||||
com r17
|
||||
and r18, r14
|
||||
and r19, r15
|
||||
and r20, r16
|
||||
and r21, r17
|
||||
or r22, r18
|
||||
or r23, r19
|
||||
or r24, r20
|
||||
or r25, r21
|
||||
rjmp md5_core_F_exit
|
||||
/*
|
||||
static
|
||||
uint32_t md5_H(uint32_t x, uint32_t y, uint32_t z){
|
||||
return (x^y^z);
|
||||
}
|
||||
*/
|
||||
; x: r22-r25
|
||||
; y: r18-r21
|
||||
; z: r14-r17
|
||||
md5_H:
|
||||
eor r22, r18
|
||||
eor r22, r14
|
||||
eor r23, r19
|
||||
eor r23, r15
|
||||
eor r24, r20
|
||||
eor r24, r16
|
||||
eor r25, r21
|
||||
eor r25, r17
|
||||
rjmp md5_core_F_exit
|
||||
/*
|
||||
static
|
||||
uint32_t md5_I(uint32_t x, uint32_t y, uint32_t z){
|
||||
return (y ^ (x | (~z)));
|
||||
}
|
||||
*/
|
||||
|
||||
jump_table:
|
||||
rjmp md5_F
|
||||
rjmp md5_G
|
||||
rjmp md5_H
|
||||
; rjmp md5_I
|
||||
|
||||
; x: r22-r25
|
||||
; y: r18-r21
|
||||
; z: r14-r17
|
||||
md5_I:
|
||||
com r14
|
||||
com r15
|
||||
com r16
|
||||
com r17
|
||||
or r22, r14
|
||||
or r23, r15
|
||||
or r24, r16
|
||||
or r25, r17
|
||||
eor r22, r18
|
||||
eor r23, r19
|
||||
eor r24, r20
|
||||
eor r25, r21
|
||||
rjmp md5_core_F_exit
|
||||
|
||||
as_table:
|
||||
; (as+0)&3 (as+3)&3 (as+1)&3 (as+2)&3
|
||||
; Z X Y
|
||||
; AS_SAVE0 AS_SAVE1 AS_SAVE2 AS_SAVE3
|
||||
.byte 1*4, 0*4, 2*4, 3*4 ;as=1
|
||||
.byte 2*4, 1*4, 3*4, 0*4 ;as=2
|
||||
.byte 3*4, 2*4, 0*4, 1*4 ;as=3
|
||||
.byte 0*4, 3*4, 1*4, 2*4 ;as=4
|
||||
|
||||
;###########################################################
|
||||
.global md5_core
|
||||
md5_core:
|
||||
mov r21, r20
|
||||
mov r20, r18
|
||||
mov r19, r16
|
||||
mov r18, r14
|
||||
; rjmp md5_core_asm
|
||||
/*
|
||||
void md5_core(uint32_t* a, void* block, uint8_t as, uint8_t s, uint8_t i, uint8_t fi){
|
||||
uint32_t t;
|
||||
md5_func_t* funcs[]={md5_F, md5_G, md5_H, md5_I};
|
||||
as &= 0x3;
|
||||
/ * a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). * /
|
||||
t = a[as] + funcs[fi](a[(as+1)&3], a[(as+2)&3], a[(as+3)&3]) + *((uint32_t*)block) + md5_T[i] ;
|
||||
a[as]=a[(as+1)&3] + ROTL32(t, s);
|
||||
}
|
||||
*/
|
||||
; a: r24-r25
|
||||
; block: r22-r23
|
||||
; as: r21
|
||||
; s: r20
|
||||
; i: r19
|
||||
; fi: r18
|
||||
P_A0 = 24
|
||||
P_A1 = 25
|
||||
P_B0 = 22
|
||||
P_B1 = 23
|
||||
P_AS = 21
|
||||
P_S = 20
|
||||
P_I = 19
|
||||
P_FI = 18
|
||||
|
||||
; x: r22-r25
|
||||
; y: r18-r21
|
||||
; z: r14-r17
|
||||
|
||||
|
||||
AS_SAVE0 = 4
|
||||
AS_SAVE1 = 5
|
||||
AS_SAVE2 = 6
|
||||
AS_SAVE3 = 7
|
||||
FI_SAVE = 8
|
||||
S_SAVE = 9
|
||||
ACCU0 = 10
|
||||
ACCU1 = 11
|
||||
ACCU2 = 12
|
||||
ACCU3 = 13
|
||||
ARG_X0 = 22
|
||||
ARG_X1 = 23
|
||||
ARG_X2 = 24
|
||||
ARG_X3 = 25
|
||||
ARG_Y0 = 18
|
||||
ARG_Y1 = 19
|
||||
ARG_Y2 = 20
|
||||
ARG_Y3 = 21
|
||||
ARG_Z0 = 14
|
||||
ARG_Z1 = 15
|
||||
ARG_Z2 = 16
|
||||
ARG_Z3 = 17
|
||||
|
||||
|
||||
md5_core_asm:
|
||||
push r16
|
||||
push r17
|
||||
push_range 4, 8
|
||||
ldi r30, lo8(T_table)
|
||||
ldi r31, hi8(T_table)
|
||||
lsl P_I
|
||||
rol r1
|
||||
lsl P_I
|
||||
rol r1
|
||||
add r30, P_I
|
||||
adc r31, r1
|
||||
clr r1
|
||||
mov FI_SAVE, r18
|
||||
/* loading T[i] into ACCU */
|
||||
lpm ACCU0, Z+
|
||||
lpm ACCU1, Z+
|
||||
lpm ACCU2, Z+
|
||||
lpm ACCU3, Z
|
||||
/* add *block to ACCU */
|
||||
movw r30, P_B0
|
||||
ld r0, Z+
|
||||
add ACCU0, r0
|
||||
ld r0, Z+
|
||||
adc ACCU1, r0
|
||||
ld r0, Z+
|
||||
adc ACCU2, r0
|
||||
ld r0, Z+
|
||||
adc ACCU3, r0
|
||||
/* add a[as+0&3] to ACCU */
|
||||
ldi r30, lo8(as_table)
|
||||
ldi r31, hi8(as_table)
|
||||
dec P_AS
|
||||
andi P_AS, 0x03
|
||||
lsl P_AS
|
||||
lsl P_AS
|
||||
add r30, r21
|
||||
adc r31, r1 ; Z points to the correct row in as_table
|
||||
lpm AS_SAVE0, Z+
|
||||
lpm AS_SAVE1, Z+
|
||||
lpm AS_SAVE2, Z+
|
||||
lpm AS_SAVE3, Z
|
||||
movw r26, r24 ; X points to a[0]
|
||||
add r26, AS_SAVE0
|
||||
adc r27, r1 ; X points at a[as&3]
|
||||
ld r0, X+
|
||||
add ACCU0, r0
|
||||
ld r0, X+
|
||||
adc ACCU1, r0
|
||||
ld r0, X+
|
||||
adc ACCU2, r0
|
||||
ld r0, X+
|
||||
adc ACCU3, r0
|
||||
mov S_SAVE, r20
|
||||
|
||||
movw r28, r24
|
||||
/* loading z value */
|
||||
movw r26, r28
|
||||
add r26, AS_SAVE1
|
||||
adc r27, r1
|
||||
ld ARG_Z0, X+
|
||||
ld ARG_Z1, X+
|
||||
ld ARG_Z2, X+
|
||||
ld ARG_Z3, X
|
||||
|
||||
/* loading x value */
|
||||
movw r26, r28
|
||||
add r26, AS_SAVE2
|
||||
adc r27, r1
|
||||
ld ARG_X0, X+
|
||||
ld ARG_X1, X+
|
||||
ld ARG_X2, X+
|
||||
ld ARG_X3, X
|
||||
|
||||
/* loading y value */
|
||||
movw r26, r28
|
||||
add r26, AS_SAVE3
|
||||
adc r27, r1
|
||||
ldi r30, pm_lo8(jump_table)
|
||||
ldi r31, pm_hi8(jump_table)
|
||||
add r30, FI_SAVE
|
||||
adc r31, r1 ; Z points to the correct entry in our jump table
|
||||
ld ARG_Y0, X+
|
||||
ld ARG_Y1, X+
|
||||
ld ARG_Y2, X+
|
||||
ld ARG_Y3, X
|
||||
|
||||
ijmp /* calls the function pointed by Z */
|
||||
md5_core_F_exit:
|
||||
|
||||
/* add ACCU to result of f() */
|
||||
add r22, ACCU0
|
||||
adc r23, ACCU1
|
||||
adc r24, ACCU2
|
||||
adc r25, ACCU3
|
||||
|
||||
/* rotate */
|
||||
mov r20, S_SAVE
|
||||
rotl32:
|
||||
cpi r20, 8
|
||||
brlo bitrotl
|
||||
mov r21, r25
|
||||
mov r25, r24
|
||||
mov r24, r23
|
||||
mov r23, r22
|
||||
mov r22, r21
|
||||
subi r20, 8
|
||||
rjmp rotl32
|
||||
bitrotl:
|
||||
mov r21, r25
|
||||
bitrotl_loop:
|
||||
tst r20
|
||||
breq fixrotl
|
||||
bitrotl_loop2:
|
||||
lsl r21
|
||||
rol r22
|
||||
rol r23
|
||||
rol r24
|
||||
rol r25
|
||||
dec r20
|
||||
brne bitrotl_loop2
|
||||
fixrotl:
|
||||
|
||||
/* add a[(as+1)&3] */
|
||||
movw r26, r28
|
||||
add r26, AS_SAVE2
|
||||
adc r27, r1
|
||||
ld r0, X+
|
||||
add r22, r0
|
||||
ld r0, X+
|
||||
adc r23, r0
|
||||
ld r0, X+
|
||||
adc r24, r0
|
||||
ld r0, X
|
||||
adc r25, r0
|
||||
|
||||
/* store result */
|
||||
movw r26, r28
|
||||
add r26, AS_SAVE0
|
||||
adc r27, r1
|
||||
st X+, r22
|
||||
st X+, r23
|
||||
st X+, r24
|
||||
st X , r25
|
||||
md5_core_exit:
|
||||
pop_range 4, 8
|
||||
pop r17
|
||||
pop r16
|
||||
ret
|
||||
|
||||
;###################################################################
|
||||
/*
|
||||
void md5_nextBlock(md5_ctx_t *state, void* block){
|
||||
uint32_t a[4];
|
||||
uint8_t m,n,i=0;
|
||||
|
||||
a[0]=state->a[0];
|
||||
a[1]=state->a[1];
|
||||
a[2]=state->a[2];
|
||||
a[3]=state->a[3];
|
||||
|
||||
/ * round 1 * /
|
||||
uint8_t s1t[]={7,12,17,22}; // 1,-1 1,4 2,-1 3,-2
|
||||
for(m=0;m<4;++m){
|
||||
for(n=0;n<4;++n){
|
||||
md5_core(a, &(((uint32_t*)block)[m*4+n]), 4-n, s1t[n],i++,0);
|
||||
}
|
||||
}
|
||||
/ * round 2 * /
|
||||
uint8_t s2t[]={5,9,14,20}; // 1,-3 1,1 2,-2 2,4
|
||||
for(m=0;m<4;++m){
|
||||
for(n=0;n<4;++n){
|
||||
md5_core(a, &(((uint32_t*)block)[(1+m*4+n*5)&0xf]), 4-n, s2t[n],i++,1);
|
||||
}
|
||||
}
|
||||
/ * round 3 * /
|
||||
uint8_t s3t[]={4,11,16,23}; // 0,4 1,3 2,0 3,-1
|
||||
for(m=0;m<4;++m){
|
||||
for(n=0;n<4;++n){
|
||||
md5_core(a, &(((uint32_t*)block)[(5-m*4+n*3)&0xf]), 4-n, s3t[n],i++,2);
|
||||
}
|
||||
}
|
||||
/ * round 4 * /
|
||||
uint8_t s4t[]={6,10,15,21}; // 1,-2 1,2 2,-1 3,-3
|
||||
for(m=0;m<4;++m){
|
||||
for(n=0;n<4;++n){
|
||||
md5_core(a, &(((uint32_t*)block)[(0-m*4+n*7)&0xf]), 4-n, s4t[n],i++,3);
|
||||
}
|
||||
}
|
||||
state->a[0] += a[0];
|
||||
state->a[1] += a[1];
|
||||
state->a[2] += a[2];
|
||||
state->a[3] += a[3];
|
||||
state->counter++;
|
||||
}
|
||||
*/
|
||||
|
||||
shift_table_1: .byte 7,12,17,22
|
||||
shift_table_2: .byte 5, 9,14,20
|
||||
shift_table_3: .byte 4,11,16,23
|
||||
shift_table_4: .byte 6,10,15,21
|
||||
|
||||
index_table_r2:
|
||||
;(1+m*4+n*5)&0xf:
|
||||
.byte 0x04, 0x18, 0x2c, 0x00
|
||||
.byte 0x14, 0x28, 0x3c, 0x10
|
||||
.byte 0x24, 0x38, 0x0c, 0x20
|
||||
.byte 0x34, 0x08, 0x1c, 0x30
|
||||
|
||||
index_table_r3:
|
||||
;(5-m*4+n*3)&0xf:
|
||||
.byte 0x14, 0x20, 0x2c, 0x38
|
||||
.byte 0x04, 0x10, 0x1c, 0x28
|
||||
.byte 0x34, 0x00, 0x0c, 0x18
|
||||
.byte 0x24, 0x30, 0x3c, 0x08
|
||||
|
||||
index_table_r4:
|
||||
;(0-m*4+n*7)&0xf:
|
||||
.byte 0x00, 0x1c, 0x38, 0x14
|
||||
.byte 0x30, 0x0c, 0x28, 0x04
|
||||
.byte 0x20, 0x3c, 0x18, 0x34
|
||||
.byte 0x10, 0x2c, 0x08, 0x24
|
||||
|
||||
APTR_REG = 2
|
||||
BPTR_REG = 4
|
||||
N_REG = 6
|
||||
M_REG = 7
|
||||
I_REG = 8
|
||||
.global md5_nextBlock
|
||||
md5_nextBlock:
|
||||
stack_alloc 16
|
||||
push_range 2, 17
|
||||
push r28
|
||||
push r29
|
||||
push r24
|
||||
push r25
|
||||
adiw r30, 1 /* Z now points to the beginning of the allocated memory */
|
||||
movw r2, r30
|
||||
movw r4, r22
|
||||
movw r26, r24
|
||||
ldi r20, 16
|
||||
1:
|
||||
ld r0, X+
|
||||
st Z+, r0
|
||||
dec r20
|
||||
brne 1b
|
||||
/* state now copied to stack memory */
|
||||
clr I_REG
|
||||
/* Round 1 */
|
||||
clr M_REG
|
||||
ldi r17, 4
|
||||
1:
|
||||
clr N_REG
|
||||
ldi r16, 4
|
||||
2:
|
||||
movw r24, APTR_REG
|
||||
movw r22, BPTR_REG
|
||||
mov r0, M_REG
|
||||
lsl r0
|
||||
lsl r0
|
||||
add r0, N_REG
|
||||
lsl r0
|
||||
lsl r0
|
||||
add r22, r0
|
||||
adc r23, r1
|
||||
mov r21, r16
|
||||
ldi r30, lo8(shift_table_1)
|
||||
ldi r31, hi8(shift_table_1)
|
||||
add r30, N_REG
|
||||
adc r31, r1
|
||||
lpm r20, Z
|
||||
mov r19, I_REG
|
||||
ldi r18, 0
|
||||
rcall md5_core_asm
|
||||
inc I_REG
|
||||
inc N_REG
|
||||
dec r16
|
||||
brne 2b
|
||||
inc M_REG
|
||||
dec r17
|
||||
brne 1b
|
||||
|
||||
/* Round 2 */
|
||||
clr M_REG
|
||||
ldi r17, 4
|
||||
1:
|
||||
clr N_REG
|
||||
ldi r16, 4
|
||||
2:
|
||||
movw r24, APTR_REG
|
||||
movw r22, BPTR_REG
|
||||
ldi r30, lo8(index_table_r2)
|
||||
ldi r31, hi8(index_table_r2)
|
||||
mov r0, M_REG
|
||||
lsl r0
|
||||
lsl r0
|
||||
add r0, N_REG
|
||||
add r30, r0
|
||||
adc r31, r1
|
||||
lpm r0, Z
|
||||
add r22, r0
|
||||
adc r23, r1
|
||||
mov r21, r16
|
||||
ldi r30, lo8(shift_table_2)
|
||||
ldi r31, hi8(shift_table_2)
|
||||
add r30, N_REG
|
||||
adc r31, r1
|
||||
lpm r20, Z
|
||||
mov r19, I_REG
|
||||
ldi r18, 1
|
||||
rcall md5_core_asm
|
||||
inc I_REG
|
||||
inc N_REG
|
||||
dec r16
|
||||
brne 2b
|
||||
inc M_REG
|
||||
dec r17
|
||||
brne 1b
|
||||
|
||||
/* Round 3 */
|
||||
clr M_REG
|
||||
ldi r17, 4
|
||||
1:
|
||||
clr N_REG
|
||||
ldi r16, 4
|
||||
2:
|
||||
movw r24, APTR_REG
|
||||
movw r22, BPTR_REG
|
||||
ldi r30, lo8(index_table_r3)
|
||||
ldi r31, hi8(index_table_r3)
|
||||
mov r0, M_REG
|
||||
lsl r0
|
||||
lsl r0
|
||||
add r0, N_REG
|
||||
add r30, r0
|
||||
adc r31, r1
|
||||
lpm r0, Z
|
||||
add r22, r0
|
||||
adc r23, r1
|
||||
mov r21, r16
|
||||
ldi r30, lo8(shift_table_3)
|
||||
ldi r31, hi8(shift_table_3)
|
||||
add r30, N_REG
|
||||
adc r31, r1
|
||||
lpm r20, Z
|
||||
mov r19, I_REG
|
||||
ldi r18, 2
|
||||
rcall md5_core_asm
|
||||
inc I_REG
|
||||
inc N_REG
|
||||
dec r16
|
||||
brne 2b
|
||||
inc M_REG
|
||||
dec r17
|
||||
brne 1b
|
||||
|
||||
/* Round 4 */
|
||||
clr M_REG
|
||||
ldi r17, 4
|
||||
1:
|
||||
clr N_REG
|
||||
ldi r16, 4
|
||||
2:
|
||||
movw r24, APTR_REG
|
||||
movw r22, BPTR_REG
|
||||
ldi r30, lo8(index_table_r4)
|
||||
ldi r31, hi8(index_table_r4)
|
||||
mov r0, M_REG
|
||||
lsl r0
|
||||
lsl r0
|
||||
add r0, N_REG
|
||||
add r30, r0
|
||||
adc r31, r1
|
||||
lpm r0, Z
|
||||
add r22, r0
|
||||
adc r23, r1
|
||||
mov r21, r16
|
||||
ldi r30, lo8(shift_table_4)
|
||||
ldi r31, hi8(shift_table_4)
|
||||
add r30, N_REG
|
||||
adc r31, r1
|
||||
lpm r20, Z
|
||||
mov r19, I_REG
|
||||
ldi r18, 3
|
||||
rcall md5_core_asm
|
||||
inc I_REG
|
||||
inc N_REG
|
||||
dec r16
|
||||
brne 2b
|
||||
inc M_REG
|
||||
dec r17
|
||||
brne 1b
|
||||
|
||||
|
||||
pop r27
|
||||
pop r26 /* X now points to the context */
|
||||
movw r30, APTR_REG
|
||||
ldi r16, 4
|
||||
1:
|
||||
ld r0, X
|
||||
ld r2, Z+
|
||||
add r0, r2
|
||||
st X+, r0
|
||||
ld r0, X
|
||||
ld r2, Z+
|
||||
adc r0, r2
|
||||
st X+, r0
|
||||
ld r0, X
|
||||
ld r2, Z+
|
||||
adc r0, r2
|
||||
st X+, r0
|
||||
ld r0, X
|
||||
ld r2, Z+
|
||||
adc r0, r2
|
||||
st X+, r0
|
||||
dec r16
|
||||
brne 1b
|
||||
|
||||
ld r0, X
|
||||
inc r0
|
||||
st X+, r0
|
||||
brne 2f
|
||||
ld r0, X
|
||||
inc r0
|
||||
st X+, r0
|
||||
brne 2f
|
||||
ld r0, X
|
||||
inc r0
|
||||
st X+, r0
|
||||
brne 2f
|
||||
ld r0, X
|
||||
inc r0
|
||||
st X+, r0
|
||||
2:
|
||||
|
||||
pop r29
|
||||
pop r28
|
||||
pop_range 2, 17
|
||||
stack_free 16
|
||||
ret
|
||||
|
||||
;###############################################################################
|
||||
/*
|
||||
void md5_lastBlock(md5_ctx_t *state, const void* block, uint16_t length_b){
|
||||
uint16_t l;
|
||||
uint8_t b[64];
|
||||
while (length_b >= 512){
|
||||
md5_nextBlock(state, block);
|
||||
length_b -= 512;
|
||||
block = ((uint8_t*)block) + 512/8;
|
||||
}
|
||||
memset(b, 0, 64);
|
||||
memcpy(b, block, length_b/8);
|
||||
/ * insert padding one * /
|
||||
l=length_b/8;
|
||||
if(length_b%8){
|
||||
uint8_t t;
|
||||
t = ((uint8_t*)block)[l];
|
||||
t |= (0x80>>(length_b%8));
|
||||
b[l]=t;
|
||||
}else{
|
||||
b[l]=0x80;
|
||||
}
|
||||
/ * insert length value * /
|
||||
if(l+sizeof(uint64_t) >= 512/8){
|
||||
md5_nextBlock(state, b);
|
||||
state->counter--;
|
||||
memset(b, 0, 64-8);
|
||||
}
|
||||
*((uint64_t*)&b[64-sizeof(uint64_t)]) = (state->counter * 512) + length_b;
|
||||
md5_nextBlock(state, b);
|
||||
}
|
||||
*/
|
||||
; state_ptr : r24,r25
|
||||
; block_ptr : r22,r23
|
||||
; length_b : r20,r21
|
||||
.global md5_lastBlock
|
||||
md5_lastBlock:
|
||||
stack_alloc_large 64
|
||||
push_range 12, 17
|
||||
push r30
|
||||
push r31
|
||||
movw r16, r20 /* length_b */
|
||||
movw r14, r22 /* block_ptr */
|
||||
movw r12, r24 /* state_ptr */
|
||||
ldi r18, 64
|
||||
2:
|
||||
cpi r17, 2 /* hi8(512) */
|
||||
brlo 2f
|
||||
1:
|
||||
movw r24, r12
|
||||
movw r22, r14
|
||||
rcall md5_nextBlock
|
||||
add r14, r18
|
||||
adc r15, r1
|
||||
subi r17, 2
|
||||
rjmp 2b
|
||||
2:
|
||||
pop r31
|
||||
pop r30
|
||||
|
||||
adiw r30, 1 /* adjust Z to point to buffer */
|
||||
movw r26, r14
|
||||
movw r24, r16
|
||||
adiw r24, 7
|
||||
|
||||
lsr r25
|
||||
ror r24
|
||||
lsr r25
|
||||
ror r24
|
||||
lsr r24 /* r24 now holds how many bytes are to copy */
|
||||
ldi r18, 64
|
||||
sub r18, r24 /* r18 will hold the amount of used bytes in buffer */
|
||||
tst r24
|
||||
4:
|
||||
breq 5f
|
||||
ld r0, X+
|
||||
st Z+, r0
|
||||
dec r24
|
||||
rjmp 4b /* Z points to the byte after msg in buffer */
|
||||
5: /* append 1-bit */
|
||||
mov r20, r16
|
||||
ldi r19, 0x80
|
||||
andi r20, 0x07
|
||||
brne bit_fucking
|
||||
st Z+, r19
|
||||
dec r18 /* 'allocate' another byte in buffer */
|
||||
rjmp after_bit_fucking
|
||||
bit_fucking:
|
||||
1:
|
||||
lsr r19
|
||||
dec r20
|
||||
brne 1b
|
||||
or r0, r19
|
||||
st -Z, r0
|
||||
adiw r30, 1
|
||||
after_bit_fucking:
|
||||
clt
|
||||
cpi r18, 8
|
||||
brmi 2f
|
||||
set /* store in t if the counter will also fit in this block (1 if fit)*/
|
||||
2:
|
||||
tst r18
|
||||
breq 2f
|
||||
1: /* fill remaning buffer with zeros */
|
||||
st Z+, r1
|
||||
dec r18
|
||||
brne 1b
|
||||
2:
|
||||
sbiw r30, 63
|
||||
sbiw r30, 1
|
||||
movw r14, r30 /* r14:r15 now points to buffer */
|
||||
brts load_counter
|
||||
/* counter does not fit, finalize this block */
|
||||
movw r24, r12
|
||||
movw r22, r14
|
||||
rcall md5_nextBlock
|
||||
movw r30, r14
|
||||
ldi r20, 64-8
|
||||
3:
|
||||
st Z+, r1
|
||||
dec r20
|
||||
brne 3b
|
||||
|
||||
load_counter:
|
||||
movw r26, r12 /* X points to state */
|
||||
adiw r26, 16
|
||||
ld r19, X+
|
||||
ld r20, X+
|
||||
ld r21, X+
|
||||
ld r22, X+
|
||||
brts post_counter_decrement /* do not decremen because counter fits */
|
||||
counter_decrement:
|
||||
subi r19, 1
|
||||
sbci r20, 0
|
||||
sbci r21, 0
|
||||
sbci r22, 0
|
||||
post_counter_decrement:
|
||||
clr r18
|
||||
clr r23
|
||||
lsl r19
|
||||
rol r20
|
||||
rol r21
|
||||
rol r22
|
||||
rol r23
|
||||
mov r18, r16 /* r16:r17 length_b */
|
||||
add r19, r17
|
||||
adc r20, r1
|
||||
adc r21, r1
|
||||
adc r22, r1
|
||||
adc r23, r1
|
||||
movw r30, r14
|
||||
adiw r30, 64-8
|
||||
st Z+, r18
|
||||
st Z+, r19
|
||||
st Z+, r20
|
||||
st Z+, r21
|
||||
st Z+, r22
|
||||
st Z+, r23
|
||||
st Z+, r1
|
||||
st Z, r1
|
||||
|
||||
sbiw r30, 63
|
||||
; sbiw r30, 1
|
||||
movw r24, r12
|
||||
movw r22, r30
|
||||
rcall md5_nextBlock
|
||||
md5_lastBlock_exit:
|
||||
pop_range 12, 17
|
||||
stack_free_large 64
|
||||
ret
|
||||
|
||||
|
||||
;###############################################################################
|
||||
|
||||
|
||||
.global md5_ctx2hash
|
||||
md5_ctx2hash:
|
||||
movw r26, r24
|
||||
movw r30, r22
|
||||
ldi r22, 16
|
||||
1:
|
||||
ld r0, Z+
|
||||
st X+, r0
|
||||
dec r22
|
||||
brne 1b
|
||||
ret
|
||||
|
||||
|
||||
;###############################################################################
|
||||
|
||||
|
||||
.global md5
|
||||
md5:
|
||||
stack_alloc 20
|
||||
push_range 8, 17
|
||||
adiw r30, 1
|
||||
movw r8, r30 /* ctx */
|
||||
movw r10, r24 /* dest */
|
||||
movw r12, r22 /* msg */
|
||||
movw r14, r18 /* length (low) */
|
||||
movw r16, r20 /* length (high) */
|
||||
movw r24, r30
|
||||
rcall md5_init
|
||||
1:
|
||||
tst r16
|
||||
brne next_round
|
||||
tst r17
|
||||
breq last_round
|
||||
next_round:
|
||||
movw r24, r8
|
||||
movw r22, r12
|
||||
rcall md5_nextBlock
|
||||
ldi r22, 64
|
||||
add r12, r22
|
||||
adc r13, r1
|
||||
ldi r22, 2
|
||||
sub r15, r22
|
||||
sbci r16, 0
|
||||
sbci r17, 0
|
||||
rjmp 1b
|
||||
last_round:
|
||||
movw r24, r8
|
||||
movw r22, r12
|
||||
movw r20, r14
|
||||
rcall md5_lastBlock
|
||||
movw r24, r10
|
||||
movw r22, r8
|
||||
rcall md5_ctx2hash
|
||||
pop_range 8, 17
|
||||
stack_free 20
|
||||
ret
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/* md5.h */
|
||||
/*
|
||||
This file is part of the AVR-Crypto-Lib.
|
||||
Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
|
||||
|
||||
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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*
|
||||
* File: md5.h
|
||||
* Author: Daniel Otte
|
||||
* Date: 31.07.2006
|
||||
* License: GPL
|
||||
* Description: Implementation of the MD5 hash algorithm as described in RFC 1321
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MD5_H_
|
||||
#define MD5_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define MD5_HASH_BITS 128
|
||||
#define MD5_HASH_BYTES (MD5_HASH_BITS/8)
|
||||
#define MD5_BLOCK_BITS 512
|
||||
#define MD5_BLOCK_BYTES (MD5_BLOCK_BITS/8)
|
||||
|
||||
|
||||
typedef struct md5_ctx_st {
|
||||
uint32_t a[4];
|
||||
uint32_t counter;
|
||||
} md5_ctx_t;
|
||||
|
||||
typedef uint8_t md5_hash_t[MD5_HASH_BYTES];
|
||||
|
||||
|
||||
void md5_init(md5_ctx_t *s);
|
||||
void md5_nextBlock(md5_ctx_t *state, const void* block);
|
||||
void md5_lastBlock(md5_ctx_t *state, const void* block, uint16_t length);
|
||||
void md5_ctx2hash(md5_hash_t* dest, const md5_ctx_t* state);
|
||||
void md5(md5_hash_t* dest, const void* msg, uint32_t length_b);
|
||||
|
||||
#endif /*MD5_H_*/
|
|
@ -4,6 +4,7 @@ ALGO_NAME := ARCFOUR
|
|||
# comment out the following line for removement of ARCFOUR from the build process
|
||||
STREAM_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := arcfour/
|
||||
$(ALGO_NAME)_OBJ := arcfour-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-arcfour-test.o $(CLI_STD) \
|
||||
nessie_stream_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,10 +4,9 @@ ALGO_NAME := ARCFOUR_C
|
|||
# comment out the following line for removement of ARCFOUR from the build process
|
||||
STREAM_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := arcfour/
|
||||
$(ALGO_NAME)_OBJ := arcfour.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-arcfour-test.o $(CLI_STD) \
|
||||
nessie_stream_test.o nessie_common.o \
|
||||
performance_test.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-arcfour-test.o $(CLI_STD) nessie_stream_test.o nessie_common.o performance_test.o
|
||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ ALGO_NAME := BASE64
|
|||
# comment out the following line for removement of base64 from the build process
|
||||
ENCODINGS += $(ALGO_NAME)
|
||||
|
||||
|
||||
$(ALGO_NAME)_DIR := base64/
|
||||
$(ALGO_NAME)_OBJ := base64_enc.o base64_dec.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-base64-test.o $(CLI_STD) \
|
||||
performance_test.o noekeon_asm.o noekeon_prng.o memxor.o
|
||||
|
|
|
@ -4,7 +4,7 @@ ALGO_NAME := BMW_C
|
|||
# comment out the following line for removement of BlueMidnightWish from the build process
|
||||
HASHES += $(ALGO_NAME)
|
||||
|
||||
|
||||
$(ALGO_NAME)_DIR := bmw/
|
||||
$(ALGO_NAME)_OBJ := bmw_small.o bmw_large.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-bmw-test.o hfal_bmw_small.o hfal_bmw_large.o $(CLI_STD) $(HFAL_STD)
|
||||
$(ALGO_NAME)_NESSIE_TEST := test nessie
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := CAST5
|
|||
# comment out the following line for removement of CAST5 from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := cast5/
|
||||
$(ALGO_NAME)_OBJ := cast5.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-cast5-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,7 +4,7 @@ ALGO_NAME := CAST6
|
|||
# comment out the following line for removement of CAST6 from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
|
||||
$(ALGO_NAME)_DIR := cast6/
|
||||
$(ALGO_NAME)_OBJ := cast6.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-cast6-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := DES
|
|||
# comment out the following line for removement of DES from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := des/
|
||||
$(ALGO_NAME)_OBJ := des.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-des-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := ENTROPIUM
|
|||
# comment out the following line for removement of PRNG from the build process
|
||||
PRNGS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := entropium/
|
||||
$(ALGO_NAME)_OBJ := entropium.o sha256-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-entropium-test.o $(CLI_STD) performance_test.o
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := GRAIN
|
|||
# comment out the following line for removement of Grain from the build process
|
||||
STREAM_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := grain/
|
||||
$(ALGO_NAME)_OBJ := grain.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-grain-test.o $(CLI_STD) \
|
||||
nessie_stream_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,9 +4,10 @@ ALGO_NAME := HMAC-MD5
|
|||
# comment out the following line for removement of HMAC-MD5 from the build process
|
||||
MACS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := hmac-md5/
|
||||
$(ALGO_NAME)_OBJ := hmac-md5.o md5-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-hmac-md5-test.o $(CLI_STD) \
|
||||
nessie_mac_test.o nessie_common.o base64_enc.o base64_dec.o
|
||||
nessie_mac_test.o nessie_common.o
|
||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := HMAC-SHA1
|
|||
# comment out the following line for removement of HMAC-SHA1 from the build process
|
||||
MACS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := hmac-sha1/
|
||||
$(ALGO_NAME)_OBJ := hmac-sha1.o sha1-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-hmac-sha1-test.o $(CLI_STD) \
|
||||
nessie_mac_test.o nessie_common.o
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := HMAC-SHA256
|
|||
# comment out the following line for removement of HMAC-SHA256 from the build process
|
||||
MACS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := hmac-sha256/
|
||||
$(ALGO_NAME)_OBJ := hmac-sha256.o sha256-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-hmac-sha256-test.o $(CLI_STD) \
|
||||
nessie_mac_test.o nessie_common.o
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := MD5
|
|||
# comment out the following line for removement of MD5 from the build process
|
||||
HASHES += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := md5/
|
||||
$(ALGO_NAME)_OBJ := md5-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-md5-test.o hfal_md5.o $(CLI_STD) $(HFAL_STD)
|
||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := MD5_C
|
|||
# comment out the following line for removement of MD5 from the build process
|
||||
HASHES += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := md5/
|
||||
$(ALGO_NAME)_OBJ := md5.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-md5-test.o hfal_md5.o $(CLI_STD) $(HFAL_STD)
|
||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := MICKEY128
|
|||
# comment out the following line for removement of Mickey128 from the build process
|
||||
STREAM_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := mickey128/
|
||||
$(ALGO_NAME)_OBJ := mickey128.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-mickey128-test.o $(CLI_STD) \
|
||||
nessie_stream_test.o nessie_common.o
|
||||
|
|
|
@ -4,7 +4,7 @@ ALGO_NAME := PRESENT
|
|||
# comment out the following line for removement of present from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
|
||||
$(ALGO_NAME)_DIR := present/
|
||||
$(ALGO_NAME)_OBJ := present.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-present-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,7 +4,7 @@ ALGO_NAME := RC5
|
|||
# comment out the following line for removement of RC5 from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
|
||||
$(ALGO_NAME)_DIR := rc5/
|
||||
$(ALGO_NAME)_OBJ := rc5.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-rc5-test.o $(CLI_STD) nessie_bc_test.o \
|
||||
nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,7 +4,7 @@ ALGO_NAME := RC6
|
|||
# comment out the following line for removement of RC6 from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
|
||||
$(ALGO_NAME)_DIR := rc6/
|
||||
$(ALGO_NAME)_OBJ := rc6.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-rc6-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := SEED
|
|||
# comment out the following line for removement of SEED from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := seed/
|
||||
$(ALGO_NAME)_OBJ := seed-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-seed-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := SEED_C
|
|||
# comment out the following line for removement of SEED from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := seed/
|
||||
$(ALGO_NAME)_OBJ := seed_C.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-seed-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,7 +4,7 @@ ALGO_NAME := SERPENT_BITSLICE
|
|||
# comment out the following line for removement of serpent from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
|
||||
$(ALGO_NAME)_DIR := serpent/
|
||||
$(ALGO_NAME)_OBJ := serpent-asm.o serpent-sboxes-bitslice-asm.o memxor.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-serpent-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,7 +4,7 @@ ALGO_NAME := SERPENT_ASM_BITSLICE
|
|||
# comment out the following line for removement of serpent from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
|
||||
$(ALGO_NAME)_DIR := serpent/
|
||||
$(ALGO_NAME)_OBJ := serpent-sboxes-bitslice-asm.o serpent-asm.o memxor.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-serpent-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,7 +4,7 @@ ALGO_NAME := SERPENT_ASM_FAST
|
|||
# comment out the following line for removement of serpent from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
|
||||
$(ALGO_NAME)_DIR := serpent/
|
||||
$(ALGO_NAME)_OBJ := serpent-asm.o serpent-sboxes-fast.o memxor.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-serpent-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,7 +4,7 @@ ALGO_NAME := SERPENT_ASM_SMALL
|
|||
# comment out the following line for removement of serpent from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
|
||||
$(ALGO_NAME)_DIR := serpent/
|
||||
$(ALGO_NAME)_OBJ := serpent-asm.o serpent-sboxes-small.o memxor.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-serpent-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,7 +4,7 @@ ALGO_NAME := SERPENT_C
|
|||
# comment out the following line for removement of serpent from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
|
||||
$(ALGO_NAME)_DIR := serpent/
|
||||
$(ALGO_NAME)_OBJ := serpent.o serpent-sboxes_c.o memxor.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-serpent-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := SHA1
|
|||
# comment out the following line for removement of SHA1 from the build process
|
||||
HASHES += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := sha1/
|
||||
$(ALGO_NAME)_OBJ := sha1-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-sha1-test.o hfal_sha1.o $(CLI_STD) $(HFAL_STD) dump-decl.o dump-asm.o
|
||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := SHA1_C
|
|||
# comment out the following line for removement of SHA1 from the build process
|
||||
HASHES += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := sha1/
|
||||
$(ALGO_NAME)_OBJ := sha1.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-sha1-test.o hfal_sha1.o dump-asm.o dump-decl.o $(CLI_STD) $(HFAL_STD)
|
||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := SHA256
|
|||
# comment out the following line for removement of SHA256 from the build process
|
||||
HASHES += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := sha256/
|
||||
$(ALGO_NAME)_OBJ := sha256-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-sha256-test.o dump-asm.o dump-decl.o hfal_sha256.o $(CLI_STD) $(HFAL_STD)
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := SHA256_C
|
|||
# comment out the following line for removement of SHA256 from the build process
|
||||
HASHES += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := sha256/
|
||||
$(ALGO_NAME)_OBJ := sha256.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-sha256-test.o $(CLI_STD) $(HFAL_STD) hfal_sha256.o dump-asm.o dump-decl.o
|
||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := SHABEA
|
|||
# comment out the following line for removement of SHABEA from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := shabea/
|
||||
$(ALGO_NAME)_OBJ := shabea.o sha256-asm.o memxor.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-shabea-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# Makefile for present
|
||||
# Makefile for shacal1
|
||||
ALGO_NAME := SHACAL1ENC
|
||||
|
||||
# comment out the following line for removement of present from the build process
|
||||
# comment out the following line for removement of shacal1 from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
|
||||
$(ALGO_NAME)_DIR := shacal1/
|
||||
$(ALGO_NAME)_OBJ := shacal1_enc.o sha1-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-shacal1_enc-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# Makefile for present
|
||||
# Makefile for shacal2
|
||||
ALGO_NAME := SHACAL2ENC
|
||||
|
||||
# comment out the following line for removement of present from the build process
|
||||
# comment out the following line for removement of shacal2 from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
|
||||
$(ALGO_NAME)_DIR := shacal2/
|
||||
$(ALGO_NAME)_OBJ := shacal2_enc.o sha256-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-shacal2_enc-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := SKIPJACK
|
|||
# comment out the following line for removement of skipjack from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := skipjack/
|
||||
$(ALGO_NAME)_OBJ := skipjack.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-skipjack-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
# Makefile for DES
|
||||
# Makefile for Triple-DES
|
||||
ALGO_NAME := TDES
|
||||
|
||||
# comment out the following line for removement of DES from the build process
|
||||
# comment out the following line for removement of Triple-DES from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := des/
|
||||
$(ALGO_NAME)_OBJ := des.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-tdes-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := TRIVIUM
|
|||
# comment out the following line for removement of Trivium from the build process
|
||||
STREAM_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := trivium/
|
||||
$(ALGO_NAME)_OBJ := trivium.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-trivium-test.o $(CLI_STD) \
|
||||
nessie_stream_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := XTEA
|
|||
# comment out the following line for removement of XTEA from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := xtea/
|
||||
$(ALGO_NAME)_OBJ := xtea-asm.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-xtea-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -4,6 +4,7 @@ ALGO_NAME := XTEA_C
|
|||
# comment out the following line for removement of XTEA from the build process
|
||||
BLOCK_CIPHERS += $(ALGO_NAME)
|
||||
|
||||
$(ALGO_NAME)_DIR := xtea/
|
||||
$(ALGO_NAME)_OBJ := xtea.o
|
||||
$(ALGO_NAME)_TEST_BIN := main-xtea-test.o $(CLI_STD) \
|
||||
nessie_bc_test.o nessie_common.o performance_test.o
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/* memxor.S */
|
||||
/*
|
||||
This file is part of the AVR-Crypto-Lib.
|
||||
Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
|
||||
|
||||
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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* File: memxor.S
|
||||
* Author: Daniel Otte
|
||||
* Date: 2008-08-07
|
||||
* License: GPLv3 or later
|
||||
* Description: memxor, XORing one block into another
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* void memxor(void* dest, const void* src, uint16_t n);
|
||||
*/
|
||||
/*
|
||||
* param dest is passed in r24:r25
|
||||
* param src is passed in r22:r23
|
||||
* param n is passed in r20:r21
|
||||
*/
|
||||
.global memxor
|
||||
memxor:
|
||||
movw r30, r24
|
||||
movw r26, r22
|
||||
movw r24, r20
|
||||
adiw r24, 0
|
||||
breq 2f
|
||||
1:
|
||||
ld r20, X+
|
||||
ld r21, Z
|
||||
eor r20, r21
|
||||
st Z+, r20
|
||||
sbiw r24, 1
|
||||
brne 1b
|
||||
2:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef MEMXOR_H_
|
||||
#define MEMXOR_H_
|
||||
#include <stdint.h>
|
||||
|
||||
void memxor(void* dest, const void* src, uint16_t n);
|
||||
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue