]> git.cryptolib.org Git - avr-crypto-lib.git/blob - shacal2_enc.c
50743a9f66c9ac0da7adc6ce3e37fa986b0f98d5
[avr-crypto-lib.git] / shacal2_enc.c
1 /**
2  * \file        shacal2_enc.c
3  * \author      Daniel Otte
4  * \date        2008-05-07
5  * \par License:
6  * GPL
7  * \brief SHACAL2 encryption only implementation.
8  * 
9  */
10
11 #include <stdint.h>
12 #include <string.h>
13 #include "sha256.h"
14 #include "shacal2_enc.h"
15
16
17 void shacal2_enc(void* buffer, void* key, uint16_t keysize_b){
18         uint8_t i;
19         sha256_ctx_t ctx, t_ctx;
20         memcpy(ctx.h, buffer, SHACAL2_BLOCKSIZE_B);
21         
22         uint8_t keybuffer[SHACAL2_KEYSIZE_B];
23         memset(keybuffer, 0, SHACAL2_KEYSIZE_B);
24         if(keysize_b>SHACAL2_KEYSIZE)
25                 keysize_b=SHACAL2_KEYSIZE;
26         memcpy(keybuffer, key, (keysize_b+7)/8);
27         
28         memcpy(t_ctx.h, buffer, SHACAL2_BLOCKSIZE_B);
29         sha256_ctx2hash((sha256_hash_t*)(&(ctx.h[0])), &t_ctx);
30         memcpy(t_ctx.h, ctx.h, SHACAL2_BLOCKSIZE_B);
31         sha256_nextBlock(&ctx, keybuffer);
32         for(i=0; i<SHACAL2_BLOCKSIZE/32; ++i){
33                 ctx.h[i] -= t_ctx.h[i];
34         }
35         sha256_ctx2hash(buffer, &ctx);
36 }
37
38
39