X-Git-Url: https://git.cryptolib.org/?p=avr-crypto-lib.git;a=blobdiff_plain;f=shacal2%2Fshacal2_enc.c;fp=shacal2%2Fshacal2_enc.c;h=b5380e57f3f4fefb6d54877266be7752e00e6600;hp=0000000000000000000000000000000000000000;hb=d32eba56ce10ea6b9eff123b50d9842673b38f2b;hpb=8f855d283a31a468ea014774c4723a8b77b81644 diff --git a/shacal2/shacal2_enc.c b/shacal2/shacal2_enc.c new file mode 100644 index 0000000..b5380e5 --- /dev/null +++ b/shacal2/shacal2_enc.c @@ -0,0 +1,57 @@ +/* shacal2_enc.c */ +/* + 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 . +*/ +/** + * \file shacal2_enc.c + * \author Daniel Otte + * \date 2008-05-07 + * \par License: + * GPL + * \brief SHACAL2 encryption only implementation. + * + */ + +#include +#include +#include "sha256.h" +#include "shacal2_enc.h" + + +void shacal2_enc(void* buffer, void* key, uint16_t keysize_b){ + uint8_t i; + sha256_ctx_t ctx, t_ctx; + memcpy(ctx.h, buffer, SHACAL2_BLOCKSIZE_B); + + uint8_t keybuffer[SHACAL2_KEYSIZE_B]; + memset(keybuffer, 0, SHACAL2_KEYSIZE_B); + if(keysize_b>SHACAL2_KEYSIZE) + keysize_b=SHACAL2_KEYSIZE; + memcpy(keybuffer, key, (keysize_b+7)/8); + + memcpy(t_ctx.h, buffer, SHACAL2_BLOCKSIZE_B); + sha256_ctx2hash((sha256_hash_t*)(&(ctx.h[0])), &t_ctx); + memcpy(t_ctx.h, ctx.h, SHACAL2_BLOCKSIZE_B); + sha256_nextBlock(&ctx, keybuffer); + for(i=0; i