Changeset 350

Show
Ignore:
Timestamp:
02/01/06 10:58:24
Author:
ben
Message:

Add IDEA.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/src/symmetric.c

    r343 r350  
    33#include <assert.h> 
    44#include <openssl/cast.h> 
     5#include <openssl/idea.h> 
    56 
    67typedef struct 
     
    115116    { memcpy(decrypt->key,key,decrypt->keysize); } 
    116117 
     118static void std_finish(ops_decrypt_t *decrypt) 
     119    { 
     120    free(decrypt->data); 
     121    decrypt->data=NULL; 
     122    } 
     123 
    117124static void cast5_init(ops_decrypt_t *decrypt) 
    118125    { 
     
    131138 
    132139    return count; 
    133     } 
    134  
    135 static void std_finish(ops_decrypt_t *decrypt) 
    136     { 
    137     free(decrypt->data); 
    138     decrypt->data=NULL; 
    139140    } 
    140141 
     
    154155    }; 
    155156 
     157static void idea_init(ops_decrypt_t *decrypt) 
     158    { 
     159    IDEA_KEY_SCHEDULE ks; 
     160 
     161    assert(decrypt->keysize == IDEA_KEY_LENGTH); 
     162 
     163    free(decrypt->data); 
     164    decrypt->data=malloc(sizeof(IDEA_KEY_SCHEDULE)); 
     165 
     166    idea_set_encrypt_key(decrypt->key,&ks); 
     167    idea_set_decrypt_key(&ks,decrypt->data); 
     168 
     169    memcpy(decrypt->civ,decrypt->iv,decrypt->blocksize); 
     170    decrypt->num=0; 
     171    } 
     172 
     173static size_t idea_decrypt(ops_decrypt_t *decrypt,void *out,const void *in, 
     174                            int count) 
     175    { 
     176    idea_cfb64_encrypt(in,out,count,decrypt->data,decrypt->civ,&decrypt->num, 
     177                       0); 
     178 
     179    return count; 
     180    } 
     181 
     182static ops_decrypt_t idea= 
     183    { 
     184    OPS_SA_IDEA, 
     185    IDEA_BLOCK, 
     186    IDEA_KEY_LENGTH, 
     187    std_set_iv, 
     188    std_set_key, 
     189    idea_init, 
     190    idea_decrypt, 
     191    std_finish, 
     192    TRAILER 
     193    }; 
     194 
    156195static ops_decrypt_t *get_proto(ops_symmetric_algorithm_t alg) 
    157196    { 
     
    161200        return &cast5; 
    162201 
     202    case OPS_SA_IDEA: 
     203        return &idea; 
     204 
    163205    default: 
    164206        assert(0);