2008-08-06 14:06:57 +00:00
|
|
|
/* noekeon_cbc_enc.S */
|
|
|
|
/*
|
2009-02-04 13:50:15 +00:00
|
|
|
This file is part of the AVR-Crypto-Lib.
|
2008-08-06 14:06:57 +00:00
|
|
|
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
|
|
|
|
* \email daniel.otte@rub.de
|
|
|
|
* \date 2008-08-06
|
|
|
|
* \license GPLv3 or later
|
2009-12-10 17:33:12 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
2008-08-06 14:06:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
.macro push_ p1:req p2:vararg
|
|
|
|
push \p1
|
2009-12-10 17:33:12 +00:00
|
|
|
.ifnb \p2
|
2008-08-06 14:06:57 +00:00
|
|
|
push_ \p2
|
|
|
|
.endif
|
|
|
|
.endm
|
|
|
|
|
|
|
|
.macro pop_ p1:req p2:vararg
|
|
|
|
pop \p1
|
2009-12-10 17:33:12 +00:00
|
|
|
.ifnb \p2
|
2008-08-06 14:06:57 +00:00
|
|
|
pop_ \p2
|
|
|
|
.endif
|
|
|
|
.endm
|
|
|
|
|
|
|
|
.extern noekeon_enc
|
|
|
|
|
|
|
|
/*
|
|
|
|
* void noekeon_cbc_enc(void* buffer, uint8_t block_cnt, const void* key)
|
|
|
|
*/
|
2009-12-10 17:33:12 +00:00
|
|
|
|
2008-08-06 14:06:57 +00:00
|
|
|
/* param buffer is passed in r24:r25
|
|
|
|
* param block_cnt is passed in r22 (r23 is 0)
|
|
|
|
* param key is passed in r20:r21
|
|
|
|
*/
|
|
|
|
.global noekeon_cbc_enc
|
|
|
|
noekeon_cbc_enc:
|
|
|
|
push r22
|
|
|
|
movw r22, r20
|
|
|
|
push_ r22, r23, r24, r25
|
|
|
|
rcall noekeon_enc
|
|
|
|
1:
|
|
|
|
pop_ r27, r26, r23, r22
|
2009-12-10 17:33:12 +00:00
|
|
|
pop r16 /* block counter */
|
2008-08-06 14:06:57 +00:00
|
|
|
dec r16
|
|
|
|
breq 9f
|
|
|
|
push r16
|
|
|
|
/* xor blocks */
|
|
|
|
movw r30, r26
|
|
|
|
adiw r30, 16
|
|
|
|
ldi r16, 16
|
|
|
|
2:
|
|
|
|
ld r17, X+
|
|
|
|
ld r18, Z
|
|
|
|
eor r18, r17
|
|
|
|
st Z+, r18
|
|
|
|
dec r16
|
|
|
|
brne 2b
|
2009-12-10 17:33:12 +00:00
|
|
|
|
2008-08-06 14:06:57 +00:00
|
|
|
/* call encryption function; X points to our new block */
|
|
|
|
push_ r22, r23, r26, r27
|
|
|
|
movw r24, r26
|
|
|
|
rcall noekeon_enc
|
|
|
|
rjmp 1b
|
2009-12-10 17:33:12 +00:00
|
|
|
9:
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|