Changeset 6d7f2a8


Ignore:
Timestamp:
Mar 17, 2010, 11:30:31 PM (10 years ago)
Author:
Nelson Elhage <nelhage@ksplice.com>
Branches:
master, release-1.6, release-1.7, release-1.8, release-1.9
Children:
e832a52
Parents:
8bd190d
git-author:
Nelson Elhage <nelhage@mit.edu> (04/29/09 23:43:39)
git-committer:
Nelson Elhage <nelhage@ksplice.com> (03/17/10 23:30:31)
Message:
zcrypt: Make encryption/decryption algorithms into a table.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zcrypt.c

    r8bd190d r6d7f2a8  
    7474#define M_SETKEY          5
    7575
    76 #define CIPHER_ERR        -1
    77 #define CIPHER_DES        0
    78 #define CIPHER_AES        1
     76enum cipher_algo {
     77  CIPHER_DES,
     78  CIPHER_AES,
     79  NCIPHER
     80};
     81
     82typedef struct {
     83  int (*encrypt)(char *keyfile, char *in, int len, FILE *out);
     84  int (*decrypt)(char *keyfile);
     85} cipher_pair;
     86
     87cipher_pair ciphers[NCIPHER] = {
     88  [CIPHER_DES] { do_encrypt_des, do_decrypt_des},
     89  [CIPHER_AES] { do_encrypt_aes, do_decrypt_aes},
     90};
    7991
    8092static void owl_zcrypt_string_to_schedule(char *keystring, des_key_schedule *schedule) {
     
    675687  }
    676688
    677   switch(cipher) {
    678   case CIPHER_DES:
    679     out = do_encrypt_des(keyfile, inbuff, buflen, outfile);
    680     break;
    681   case CIPHER_AES:
    682     out = do_encrypt_aes(keyfile, inbuff, buflen, outfile);
    683     break;
    684   }
     689  out = ciphers[cipher].encrypt(keyfile, inbuff, buflen, outfile);
    685690
    686691  if (zephyr)
     
    829834int do_decrypt(char *keyfile, int cipher)
    830835{
    831   switch(cipher) {
    832   case CIPHER_DES:
    833     return do_decrypt_des(keyfile);
    834   case CIPHER_AES:
    835     return do_decrypt_aes(keyfile);
    836   default:
    837     return FALSE;
    838   }
     836  return ciphers[cipher].decrypt(keyfile);
    839837}
    840838
Note: See TracChangeset for help on using the changeset viewer.