des.c File Reference

DES (Data Encryption Standard) More...

#include "core/crypto.h"
#include "cipher/des.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 
#define ROL28(a, n)   ((((a) << (n)) | ((a) >> (28 - (n)))) & 0x0FFFFFFF)
 
#define DES_IP(left, right)
 
#define DES_FP(left, right)
 
#define DES_ROUND(left, right, ks)
 
#define DES_PC1(left, right)
 

Functions

error_t desInit (DesContext *context, const uint8_t *key, size_t keyLen)
 Initialize a DES context using the supplied key. More...
 
void desEncryptBlock (DesContext *context, const uint8_t *input, uint8_t *output)
 Encrypt a 8-byte block using DES algorithm. More...
 
void desDecryptBlock (DesContext *context, const uint8_t *input, uint8_t *output)
 Decrypt a 8-byte block using DES algorithm. More...
 

Variables

const CipherAlgo desCipherAlgo
 

Detailed Description

DES (Data Encryption Standard)

License

Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneCrypto Open.

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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Description

DES is an encryption algorithm designed to encipher and decipher blocks of 64 bits under control of a 64-bit key. Refer to FIPS 46-3 for more details

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.0

Definition in file des.c.

Macro Definition Documentation

◆ DES_FP

#define DES_FP (   left,
  right 
)
Value:
{ \
left = ROR32(left, 1); \
right = ROR32(right, 1); \
temp = ((left >> 1) ^ right) & 0x55555555; \
right ^= temp; \
left ^= temp << 1; \
temp = ((right >> 8) ^ left) & 0x00FF00FF; \
left ^= temp; \
right ^= temp << 8; \
temp = ((right >> 2) ^ left) & 0x33333333; \
left ^= temp; \
right ^= temp << 2; \
temp = ((left >> 16) ^ right) & 0x0000FFFF; \
right ^= temp; \
left ^= temp << 16; \
temp = ((left >> 4) ^ right) & 0x0F0F0F0F; \
right ^= temp; \
left ^= temp << 4; \
}
#define ROR32(a, n)
Definition: crypto.h:855

Definition at line 70 of file des.c.

◆ DES_IP

#define DES_IP (   left,
  right 
)
Value:
{ \
temp = ((left >> 4) ^ right) & 0x0F0F0F0F; \
right ^= temp; \
left ^= temp << 4; \
temp = ((left >> 16) ^ right) & 0x0000FFFF; \
right ^= temp; \
left ^= temp << 16; \
temp = ((right >> 2) ^ left) & 0x33333333; \
left ^= temp; \
right ^= temp << 2; \
temp = ((right >> 8) ^ left) & 0x00FF00FF; \
left ^= temp; \
right ^= temp << 8; \
temp = ((left >> 1) ^ right) & 0x55555555; \
right ^= temp; \
left ^= temp << 1; \
left = ROL32(left, 1); \
right = ROL32(right, 1); \
}
#define ROL32(a, n)
Definition: crypto.h:849

Definition at line 48 of file des.c.

◆ DES_PC1

#define DES_PC1 (   left,
  right 
)
Value:
{ \
uint32_t temp; \
temp = ((left >> 4) ^ right) & 0x0F0F0F0F; \
right ^= temp; \
left ^= (temp << 4); \
temp = ((right >> 16) ^ left) & 0x0000FFFF; \
left ^= temp; \
right ^= (temp << 16); \
temp = ((left >> 2) ^ right) & 0x33333333; \
right ^= temp; \
left ^= (temp << 2); \
temp = ((right >> 16) ^ left) & 0x0000FFFF; \
left ^= temp; \
right ^= (temp << 16); \
temp = ((left >> 1) ^ right) & 0x55555555; \
right ^= temp; \
left ^= (temp << 1); \
temp = ((right >> 8) ^ left) & 0x00FF00FF; \
left ^= temp; \
right ^= (temp << 8); \
temp = ((left >> 1) ^ right) & 0x55555555; \
right ^= temp; \
left ^= (temp << 1); \
temp = (left << 8) | ((right >> 20) & 0x000000F0); \
left = ((right << 20) & 0x0FF00000); \
left |= ((right << 4) & 0x000FF000); \
left |= ((right >> 12) & 0x00000FF0); \
left |= ((right >> 28) & 0x0000000F); \
right = temp >> 4; \
}

Definition at line 110 of file des.c.

◆ DES_ROUND

#define DES_ROUND (   left,
  right,
  ks 
)
Value:
{ \
temp = right ^ *(ks); \
left ^= sp2[(temp >> 24) & 0x3F]; \
left ^= sp4[(temp >> 16) & 0x3F]; \
left ^= sp6[(temp >> 8) & 0x3F]; \
left ^= sp8[temp & 0x3F]; \
temp = ROR32(right, 4) ^ *(ks + 1); \
left ^= sp1[(temp >> 24) & 0x3F]; \
left ^= sp3[(temp >> 16) & 0x3F]; \
left ^= sp5[(temp >> 8) & 0x3F]; \
left ^= sp7[temp & 0x3F]; \
temp = right; \
right = left; \
left = temp; \
}
#define ROR32(a, n)
Definition: crypto.h:855

Definition at line 92 of file des.c.

◆ ROL28

#define ROL28 (   a,
  n 
)    ((((a) << (n)) | ((a) >> (28 - (n)))) & 0x0FFFFFFF)

Definition at line 45 of file des.c.

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 35 of file des.c.

Function Documentation

◆ desDecryptBlock()

void desDecryptBlock ( DesContext context,
const uint8_t *  input,
uint8_t *  output 
)

Decrypt a 8-byte block using DES algorithm.

Parameters
[in]contextPointer to the DES context
[in]inputCiphertext block to decrypt
[out]outputPlaintext block resulting from decryption

Definition at line 380 of file des.c.

◆ desEncryptBlock()

void desEncryptBlock ( DesContext context,
const uint8_t *  input,
uint8_t *  output 
)

Encrypt a 8-byte block using DES algorithm.

Parameters
[in]contextPointer to the DES context
[in]inputPlaintext block to encrypt
[out]outputCiphertext block resulting from encryption

Definition at line 341 of file des.c.

◆ desInit()

error_t desInit ( DesContext context,
const uint8_t *  key,
size_t  keyLen 
)

Initialize a DES context using the supplied key.

Parameters
[in]contextPointer to the DES context to initialize
[in]keyPointer to the key
[in]keyLenLength of the key (must be set to 8)
Returns
Error code

Definition at line 269 of file des.c.

Variable Documentation

◆ desCipherAlgo

const CipherAlgo desCipherAlgo
Initial value:
=
{
"DES",
sizeof(DesContext),
NULL,
NULL,
}
DES algorithm context.
Definition: des.h:50
error_t desInit(DesContext *context, const uint8_t *key, size_t keyLen)
Initialize a DES context using the supplied key.
Definition: des.c:269
void desEncryptBlock(DesContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 8-byte block using DES algorithm.
Definition: des.c:341
void(* CipherAlgoDecryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:1030
void desDecryptBlock(DesContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using DES algorithm.
Definition: des.c:380
#define DES_BLOCK_SIZE
Definition: des.h:36
error_t(* CipherAlgoInit)(void *context, const uint8_t *key, size_t keyLen)
Definition: crypto.h:1026
void(* CipherAlgoEncryptBlock)(void *context, const uint8_t *input, uint8_t *output)
Definition: crypto.h:1029

Definition at line 247 of file des.c.