www.pudn.com > serpent.rar > ecb_e_m.c


/* 
  $Id: ecb_e_m.c,v 1.9 1998/06/10 18:00:22 fms Exp $ 
 
  # This file is part of the C reference implementation of Serpent. 
  # 
  # Written by Frank Stajano, 
  # Olivetti Oracle Research Laboratory  and 
  # Cambridge University Computer Laboratory . 
  #  
  # (c) 1998 Olivetti Oracle Research Laboratory (ORL) 
  # 
  # Original (Python) Serpent reference development started on 1998 02 12. 
  # C implementation development started on 1998 03 04. 
  # 
  # Serpent cipher invented by Ross Anderson, Eli Biham, Lars Knudsen. 
  # Serpent is a candidate for the Advanced Encryption Standard. 
  
*/ 
 
/* -------------------------------------------------- */ 
#include  
#include "serpent-api.h" 
#include "serpent-aux.h" 
/* -------------------------------------------------- */ 
EMBED_RCS(ecb_e_m_c, 
          "$Id: ecb_e_m.c,v 1.9 1998/06/10 18:00:22 fms Exp $") 
 
 
int main(void) { 
  int i, j, bitsPerShortKey, result; 
  BLOCK plainText, cipherText, CT_9998; 
  KEY binaryKey; 
  char asciiKey[HEX_DIGITS_PER_KEY+1]; 
  keyInstance key; 
  cipherInstance cipher; 
 
 
  /* The hack that remembers CT_9998 only works if... */ 
  assert(BITS_PER_KEY <= 2*BITS_PER_BLOCK); 
  /* ...otherwise we'd have to remember more than just CT_9998. */ 
 
  printHeader("ecb_e_m", "Electronic Codebook (ECB) Mode - ENCRYPTION", 
              "Monte Carlo Test"); 
 
  for(bitsPerShortKey=BITS_PER_SHORTEST_KEY; bitsPerShortKey<=BITS_PER_KEY; 
      bitsPerShortKey+=BITS_PER_KEY_STEP) { 
    result = stringToWords("00000000000000000000000000000000", plainText, 
                           WORDS_PER_BLOCK); 
    if (result != TRUE) goto error; 
 
    printf("KEYSIZE=%d\n\n", bitsPerShortKey); 
 
    /* Construct (backwards) an ascii key of all 0s, of length 
       bitsPerShortKey bits. */ 
    i=bitsPerShortKey/BITS_PER_HEX_DIGIT; 
    asciiKey[i] = 0; /* terminating null */  
    for (i--; i >=0; i--) { 
      asciiKey[i] = '0'; 
    } 
 
    result = cipherInit(&cipher, MODE_ECB, 0); 
    if (result != TRUE) goto error; 
 
    for(i=0; i