Commit cadc7ac6 authored by Rafael Sevilla's avatar Rafael Sevilla Committed by Niels Möller

*** empty log message ***

Rev: src/symmetric/Makefile.am.in:1.17
Rev: src/symmetric/include/rijndael.h:1.1
Rev: src/symmetric/include/serpent.h:1.1
Rev: src/symmetric/rijndael.c:1.1
Rev: src/symmetric/rijndael_test.c:1.1
Rev: src/symmetric/serpent.c:1.1
Rev: src/symmetric/serpentsboxes.h:1.1
parent ef76209d
......@@ -6,7 +6,7 @@ BODY:
AUTOMAKE_OPTIONS = foreign
noinst_LIBRARIES = libsymmetric.a
noinst_PROGRAMS = desTest desdata bf_test twofish_test generate_q
noinst_PROGRAMS = desTest desdata bf_test twofish_test generate_q rijndael_test
Makefile.am: Makefile.am.in
(cd $(top_srcdir) && $(MAKE) src/symmetric/Makefile.am)
......@@ -22,7 +22,8 @@ BUILT_SOURCES = desSmallFips.c desSmallCore.c desQuickFips.c desQuickCore.c
libsymmetric_a_SOURCES = desCode.h desKerb.c desUtil.c desQuick.c \
$(BUILT_SOURCES) \
sha.c md5.c idea.c arcfour.c cast.c blowfish.c twofish.c
sha.c md5.c idea.c arcfour.c cast.c blowfish.c twofish.c rijndael.c \
serpent.c
# Generate DES headers.
$(des_headers): desdata
......
/*
*
* Rijndael is a 128/192/256-bit block cipher that accepts key sizes of
* 128, 192, or 256 bits, designed by Joan Daemen and Vincent Rijmen. See
* http://www.esat.kuleuven.ac.be/~rijmen/rijndael/ for details.
*/
#if !defined(RIJNDAEL_H)
#define RIJNDAEL_H
#include <stdlib.h>
#include "crypto_types.h"
/* Other block sizes and key lengths are possible, but in the context of
* the ssh protocols, 256 bits is the default. */
#define RIJNDAEL_BLOCKSIZE 16
#define RIJNDAEL_KEYSIZE 32
/* Allow keys of size 128 <= bits <= 256 */
#define RIJNDAEL_MIN_KEYSIZE 16
#define RIJNDAEL_MAX_KEYSIZE 32
typedef struct {
UINT32 keys[60]; /* maximum size of key schedule */
UINT32 ikeys[60]; /* inverse key schedule */
int nrounds; /* number of rounds to use for our key size */
} RIJNDAEL_context;
/* This basically performs Rijndael's key scheduling algorithm, as it's the
* only initialization required anyhow. The key size is specified in bytes,
* but the only valid values are 16 (128 bits), 24 (192 bits), and 32 (256
* bits). If a value other than these three is specified, the key will be
* truncated to the closest value less than the key size specified, e.g.
* specifying 7 will use only the first 6 bytes of the key given. DO NOT
* PASS A VALUE LESS THAN 16 TO KEYSIZE! */
void
rijndael_setup(RIJNDAEL_context *ctx, size_t keysize, const UINT8 *key);
/*
* rijndael_encrypt()
*
* Encrypt 16 bytes of data with the Rijndael algorithm. Before this
* function can be used, rijndael_setup must be used in order to initialize
* Rijndael's key schedule.
*
* This function always encrypts 16 bytes of plaintext to 16 bytes of
* ciphertext. The memory areas of the plaintext and the ciphertext can
* overlap.
*/
void
rijndael_encrypt(RIJNDAEL_context *context,
const UINT8 *plaintext,
UINT8 *ciphertext);
/*
* rijndael_decrypt()
*
* Decrypt 16 bytes of data with the Rijndael algorithm.
*
* Before this function can be used, rijndael_setup() must be used in order
* to set up the key schedule required for the decryption algorithm.
*
* This function always decrypts 16 bytes of ciphertext to 16 bytes of
* plaintext. The memory areas of the plaintext and the ciphertext can
* overlap.
*/
void
rijndael_decrypt(RIJNDAEL_context *context,
const UINT8 *ciphertext,
UINT8 *plaintext);
#endif /* RIJNDAEL_H */
/*
*
* Serpent is a 128-bit block cipher that accepts a key size of 256 bits,
* designed by Ross Anderson, Eli Biham, and Lars Knudsen. See
* http://www.cl.cam.ac.uk/~rja14/serpent.html for details.
*/
#if !defined(SERPENT_H)
#define SERPENT_H
#include <stdlib.h>
#include "crypto_types.h"
#define SERPENT_BLOCKSIZE 16
/* Other key lengths are possible, but we only use 256 bits. Besides, the
design of Serpent makes other key lengths useless; they cheated with the
AES requirements, using a 256-bit key length exclusively and just padding
it out if the desired key length was less, so there really is no advantage
to using key lengths less than 256 bits. */
#define SERPENT_KEYSIZE 32
typedef struct {
UINT32 keys[33][4]; /* key schedule */
} SERPENT_context;
/* This performs Serpent's key scheduling algorithm. */
void
serpent_setup(SERPENT_context *ctx, const UINT8 key[32]);
/*
* serpent_encrypt()
*
* Encrypt 16 bytes of data with the Serpent algorithm. Before this
* function can be used, serpent_setup must be used in order to initialize
* Serpent's key schedule.
*
* This function always encrypts 16 bytes of plaintext to 16 bytes of
* ciphertext. The memory areas of the plaintext and the ciphertext can
* overlap.
*/
void
serpent_encrypt(SERPENT_context *context,
const UINT8 *plaintext,
UINT8 *ciphertext);
/*
* serpent_decrypt()
*
* Decrypt 16 bytes of data with the Serpent algorithm.
*
* Before this function can be used, serpent_setup() must be used in order
* to set up the key schedule required for the decryption algorithm.
*
* This function always decrypts 16 bytes of ciphertext to 16 bytes of
* plaintext. The memory areas of the plaintext and the ciphertext can
* overlap.
*/
void
serpent_decrypt(SERPENT_context *context,
const UINT8 *ciphertext,
UINT8 *plaintext);
#endif /* SERPENT_H */
This diff is collapsed.
#include <stdio.h>
#include <stdlib.h>
#include "rijndael.h"
int main(void)
{
RIJNDAEL_context ctx;
UINT8 key[32];
UINT8 text[16];
int i, j;
for (i=0; i<16; i++)
text[i] = i;
for (i=0; i<32; i++)
key[i] = 0;
key[0] = 1;
for (j=16; j<=32; j+=8) {
rijndael_setup(&ctx, j, key);
printf("\nBlock Size = 128 bits, Key Size = %d bits\n", j*8);
printf("\nPlain= ");
for (i=0; i<16; i++)
printf("%2x", text[i]);
printf("\n");
rijndael_encrypt(&ctx, text, text);
printf("Encrypt= ");
for (i=0; i<16; i++)
printf("%02x", text[i]);
printf("\nDecrypt= ");
rijndael_decrypt(&ctx, text, text);
for (i=0; i<16; i++)
printf("%2x", text[i]);
printf("\n");
}
return(0);
}
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment