X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=des.c;h=0ad3361cbd6188a99b06229a6717c52eeb45499c;hb=17332291e15183d71d88ed868275e3cb53917180;hp=0a47906afcb0fbce6d32e2fcaf4ed31ea768b3fe;hpb=79c9a6582ba071646a3062175715f59ebe210603;p=avr-crypto-lib.git diff --git a/des.c b/des.c index 0a47906..0ad3361 100644 --- a/des.c +++ b/des.c @@ -1,15 +1,34 @@ +/* des.c */ +/* + This file is part of the 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 des.c - * \author Daniel Otte - * \date 2007-06-16 - * \brief DES and EDE-DES implementation - * \par License - * GPL + * \file des.c + * \author Daniel Otte + * \email daniel.otte@rub.de + * \date 2007-06-16 + * \brief DES and EDE-DES implementation + * \license GPLv3 or later * */ #include "config.h" #include "debug.h" #include "uart.h" +#include #include #include #include @@ -188,7 +207,7 @@ prog_uint8_t shiftkeyinv_permtab[] = { #define ROTTABLE_INV 0x3F7E /******************************************************************************/ -void permute(prog_uint8_t *ptable, uint8_t *in, uint8_t *out){ +void permute(prog_uint8_t *ptable, const uint8_t *in, uint8_t *out){ uint8_t ib, ob; /* in-bytes and out-bytes */ uint8_t byte, bit; /* counter for bit and byte */ ib = pgm_read_byte(&(ptable[0])); @@ -283,15 +302,15 @@ uint32_t des_f(uint32_t r, uint8_t* kr){ /******************************************************************************/ -void des_encrypt(uint8_t* out, uint8_t* in, uint8_t* key){ +void des_enc(void* out, const void* in, const void* key){ #define R *((uint32_t*)&(data[4])) #define L *((uint32_t*)&(data[0])) uint8_t data[8],kr[6],k[7]; uint8_t i; - permute((prog_uint8_t*)ip_permtab, in, data); - permute((prog_uint8_t*)pc1_permtab, key, k); + permute((prog_uint8_t*)ip_permtab, (uint8_t*)in, data); + permute((prog_uint8_t*)pc1_permtab, (uint8_t*)key, k); for(i=0; i<8; ++i){ shiftkey(k); if(ROTTABLE&((1<<((i<<1)+0))) ) @@ -311,20 +330,20 @@ void des_encrypt(uint8_t* out, uint8_t* in, uint8_t* key){ L ^= R; R ^= L; - permute((prog_uint8_t*)inv_ip_permtab, data, out); + permute((prog_uint8_t*)inv_ip_permtab, data, (uint8_t*)out); } /******************************************************************************/ -void des_decrypt(uint8_t* out, uint8_t* in, uint8_t* key){ +void des_dec(void* out, const void* in, const uint8_t* key){ #define R *((uint32_t*)&(data[4])) #define L *((uint32_t*)&(data[0])) uint8_t data[8],kr[6],k[7]; int8_t i; - permute((prog_uint8_t*)ip_permtab, in, data); - permute((prog_uint8_t*)pc1_permtab, key, k); + permute((prog_uint8_t*)ip_permtab, (uint8_t*)in, data); + permute((prog_uint8_t*)pc1_permtab, (uint8_t*)key, k); for(i=7; i>=0; --i){ permute((prog_uint8_t*)pc2_permtab, k, kr); @@ -347,23 +366,23 @@ void des_decrypt(uint8_t* out, uint8_t* in, uint8_t* key){ L ^= R; R ^= L; - permute((prog_uint8_t*)inv_ip_permtab, data, out); + permute((prog_uint8_t*)inv_ip_permtab, data, (uint8_t*)out); } /******************************************************************************/ -void tdes_encrypt(uint8_t* out, uint8_t* in, uint8_t* key){ - des_encrypt(out, in, key + 0); - des_decrypt(out, out, key + 8); - des_encrypt(out, out, key +16); +void tdes_enc(void* out, void* in, const void* key){ + des_enc(out, in, (uint8_t*)key + 0); + des_dec(out, out, (uint8_t*)key + 8); + des_enc(out, out, (uint8_t*)key +16); } /******************************************************************************/ -void tdes_decrypt(uint8_t* out, uint8_t* in, uint8_t* key){ - des_decrypt(out, in, key + 0); - des_encrypt(out, out, key + 8); - des_decrypt(out, out, key +16); +void tdes_dec(void* out, void* in, const uint8_t* key){ + des_dec(out, in, (uint8_t*)key + 0); + des_enc(out, out, (uint8_t*)key + 8); + des_dec(out, out, (uint8_t*)key +16); } /******************************************************************************/