Changeset 470

Show
Ignore:
Timestamp:
04/22/07 17:05:42
Author:
ben
Message:

Untested, non-functional, partial encryption implementation.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/examples/Makefile.template

    r460 r470  
    1414 
    1515test: test-dump test-verify test-verify-armoured test-create-key \ 
    16       test-v3-secring Makefile 
     16      test-v3-secring Makefile test-encrypt 
    1717 
    1818../src/standard/libops_std.a:: 
     
    112112        ./packet-dump -p ../test/v3-secring.pgp 
    113113 
     114$(SCRATCH)/t1.sec $(SCRATCH)/t1.pub: 
     115        ./create-gpg-key.sh 
     116 
     117test-encrypt: encrypt $(SCRATCH)/t1.pub 
     118        echo 'Test encryption' | ./encrypt $(SCRATCH)/t1.pub "OPS Test (This is a test) <ops@links.org>" > $(SCRATCH)/encrypted 
     119        gpg --no-default-keyring --secret-keyring $(SCRATCH)/t1.sec $(SCRATCH)/encrypted 
     120 
    114121include .depend 
  • openpgpsdk/trunk/include/openpgpsdk/crypto.h

    r438 r470  
    2828    }; 
    2929 
    30 typedef void ops_decrypt_set_iv_t(ops_decrypt_t *decrypt, 
    31                                   const unsigned char *iv); 
    32 typedef void ops_decrypt_set_key_t(ops_decrypt_t *decrypt, 
    33                                    const unsigned char *key); 
    34 typedef void ops_decrypt_init_t(ops_decrypt_t *decrypt); 
    35 typedef void ops_decrypt_resync_t(ops_decrypt_t *decrypt); 
    36 //typedef size_t ops_decrypt_decrypt_t(ops_decrypt_t *decrypt,void *out, 
    37 //                                   const void *in,int count); 
    38 typedef void ops_decrypt_block_encrypt_t(ops_decrypt_t *decrypt,void *out, 
    39                                          const void *in); 
    40 typedef void ops_decrypt_finish_t(ops_decrypt_t *decrypt); 
     30typedef void ops_crypt_set_iv_t(ops_crypt_t *crypt, 
     31                                const unsigned char *iv); 
     32typedef void ops_crypt_set_key_t(ops_crypt_t *crypt, 
     33                                 const unsigned char *key); 
     34typedef void ops_crypt_init_t(ops_crypt_t *crypt); 
     35typedef void ops_crypt_resync_t(ops_crypt_t *crypt); 
     36typedef void ops_crypt_block_encrypt_t(ops_crypt_t *crypt,void *out, 
     37                                       const void *in); 
     38typedef void ops_crypt_finish_t(ops_crypt_t *crypt); 
    4139 
    4240/** _ops_decrypt_t */ 
    43 struct _ops_decrypt_t 
     41struct _ops_crypt_t 
    4442    { 
    4543    ops_symmetric_algorithm_t algorithm; 
    4644    size_t blocksize; 
    4745    size_t keysize; 
    48     ops_decrypt_set_iv_t *set_iv; /* Call this before init! */ 
    49     ops_decrypt_set_iv_t *set_key; /* Call this before init! */ 
    50     ops_decrypt_init_t *base_init; 
    51     ops_decrypt_resync_t *resync; 
    52     //    ops_decrypt_decrypt_t *decrypt; 
    53     ops_decrypt_block_encrypt_t *block_encrypt; 
    54     ops_decrypt_finish_t *finish; 
     46    ops_crypt_set_iv_t *set_iv; /* Call this before decrypt init! */ 
     47    ops_crypt_set_key_t *set_key; /* Call this before init! */ 
     48    ops_crypt_init_t *base_init; 
     49    ops_crypt_resync_t *decrypt_resync; 
     50    ops_crypt_block_encrypt_t *block_encrypt; 
     51    ops_crypt_finish_t *decrypt_finish; 
    5552    unsigned char iv[OPS_MAX_BLOCK_SIZE]; 
    5653    unsigned char civ[OPS_MAX_BLOCK_SIZE]; 
     
    7976int ops_rsa_public_decrypt(unsigned char *out,const unsigned char *in, 
    8077                           size_t length,const ops_rsa_public_key_t *rsa); 
     78int ops_rsa_public_encrypt(unsigned char *out,const unsigned char *in, 
     79                           size_t length,const ops_rsa_public_key_t *rsa); 
    8180int ops_rsa_private_encrypt(unsigned char *out,const unsigned char *in, 
    8281                            size_t length,const ops_rsa_secret_key_t *srsa, 
     
    9291                     ops_parse_info_t *parse_info); 
    9392 
    94 void ops_decrypt_any(ops_decrypt_t *decrypt,ops_symmetric_algorithm_t alg); 
    95 void ops_decrypt_init(ops_decrypt_t *decrypt); 
    96 size_t ops_decrypt_decrypt(ops_decrypt_t *decrypt,void *out,const void *in, 
    97                          size_t count); 
     93void ops_crypt_any(ops_crypt_t *decrypt,ops_symmetric_algorithm_t alg); 
     94void ops_decrypt_init(ops_crypt_t *decrypt); 
     95size_t ops_decrypt(ops_crypt_t *decrypt,void *out,const void *in, 
     96                   size_t count); 
     97size_t ops_encrypt(ops_crypt_t *encrypt,void *out,const void *in, 
     98                   size_t count); 
    9899 
    99 void ops_reader_push_decrypt(ops_parse_info_t *pinfo,ops_decrypt_t *decrypt, 
     100void ops_reader_push_decrypt(ops_parse_info_t *pinfo,ops_crypt_t *decrypt, 
    100101                             ops_region_t *region); 
    101102void ops_reader_pop_decrypt(ops_parse_info_t *pinfo); 
     
    107108int ops_decrypt_mpi(unsigned char *buf,unsigned buflen,const BIGNUM *encmpi, 
    108109                    const ops_secret_key_t *skey); 
     110ops_boolean_t ops_encrypt_mpi(const unsigned char *buf, size_t buflen, 
     111                              const ops_public_key_t *pkey, 
     112                              ops_pk_session_key_parameters_t *spk); 
     113 
    109114 
    110115// Encrypt everything that's written 
  • openpgpsdk/trunk/include/openpgpsdk/packet-parse.h

    r457 r470  
    9494void ops_parse_info_delete(ops_parse_info_t *pinfo); 
    9595ops_error_t *ops_parse_info_get_errors(ops_parse_info_t *pinfo); 
    96 ops_decrypt_t *ops_parse_get_decrypt(ops_parse_info_t *pinfo); 
     96ops_crypt_t *ops_parse_get_decrypt(ops_parse_info_t *pinfo); 
    9797 
    9898void ops_parse_cb_set(ops_parse_info_t *pinfo,ops_parse_cb_t *cb,void *arg); 
  • openpgpsdk/trunk/include/openpgpsdk/types.h

    r388 r470  
    2525typedef enum ops_content_tag_t ops_content_tag_t; 
    2626 
    27 typedef struct _ops_decrypt_t ops_decrypt_t; 
     27typedef struct _ops_crypt_t ops_crypt_t; 
    2828 
    2929/** ops_hash_t */ 
  • openpgpsdk/trunk/src/advanced/Makefile.template

    r437 r470  
    1313        adv_signature.o adv_compress.o adv_packet-show.o adv_create.o \ 
    1414        adv_validate.o adv_lists.o adv_armour.o adv_errors.o \ 
    15         adv_symmetric.o adv_crypto.o 
     15        adv_symmetric.o adv_crypto.o random.o 
    1616 
    1717headers: 
  • openpgpsdk/trunk/src/advanced/adv_create.c

    r452 r470  
    44#include <openpgpsdk/create.h> 
    55#include <openpgpsdk/keyring.h> 
     6#include <openpgpsdk/random.h> 
    67#include "keyring_local.h" 
    78#include <openpgpsdk/packet.h> 
     
    669670    // Make sure the finaliser has been called. 
    670671    assert(!info->winfo.finaliser); 
    671     // Makew sure this is a stacked writer 
     672    // Make sure this is a stacked writer 
    672673    assert(info->winfo.next); 
    673674    if(info->winfo.destroyer) 
     
    752753    ops_pk_session_key_t *session_key=ops_mallocz(sizeof *session_key); 
    753754 
     755    assert(key->type == OPS_PTAG_CT_PUBLIC_KEY); 
    754756    session_key->version=OPS_PKSK_V3; 
    755757    memcpy(session_key->key_id, key->key_id, sizeof session_key->key_id); 
    756     // XXX: finish filling in the structure 
     758 
     759    assert(key->key.pkey.algorithm == OPS_PKA_RSA); 
     760    session_key->algorithm=key->key.pkey.algorithm; 
     761    session_key->symmetric_algorithm=OPS_SA_AES_256; 
     762    ops_random(session_key->key, 256/8); 
     763 
     764    if(!ops_encrypt_mpi(session_key->key, 256/8, &key->key.pkey, &session_key->parameters)) 
     765        return NULL; 
     766 
    757767    return session_key; 
    758768    } 
    759769 
    760 // XXX: should these be common and just be called ops_crypt_*? 
    761 typedef struct _ops_encrypt_t ops_encrypt_t; 
    762 typedef void ops_encrypt_set_iv_t(ops_encrypt_t *encrypt, 
    763                                   const unsigned char *iv); 
    764 typedef void ops_encrypt_init_t(ops_encrypt_t *encrypt); 
    765 typedef void ops_encrypt_resync_t(ops_encrypt_t *encrypt); 
    766 typedef void ops_encrypt_block_encrypt_t(ops_encrypt_t *encrypt,void *out, 
    767                                          const void *in); 
    768 typedef void ops_encrypt_finish_t(ops_encrypt_t *encrypt); 
    769  
    770 /** _ops_encrypt_t */ 
    771 struct _ops_encrypt_t 
    772     { 
    773     ops_symmetric_algorithm_t algorithm; 
    774     size_t blocksize; 
    775     size_t keysize; 
    776     //    ops_encrypt_set_iv_t *set_iv; /* Call this before init! */ 
    777     ops_encrypt_set_iv_t *set_key; /* Call this before init! */ 
    778     ops_encrypt_init_t *base_init; /* Once the key is set, call this */ 
    779     ops_encrypt_resync_t *resync; 
    780     //    ops_decrypt_decrypt_t *decrypt; 
    781     ops_encrypt_block_encrypt_t *block_encrypt; 
    782     ops_encrypt_finish_t *finish; 
    783     unsigned char iv[OPS_MAX_BLOCK_SIZE]; 
    784     unsigned char civ[OPS_MAX_BLOCK_SIZE]; 
    785     unsigned char siv[OPS_MAX_BLOCK_SIZE]; /* Needed for weird v3 resync */ 
    786     unsigned char key[OPS_MAX_KEY_SIZE]; 
    787     size_t num; 
    788     void *data; 
    789     }; 
    790  
    791770typedef struct 
    792771    { 
    793     ops_encrypt_t *encrypter; 
     772    ops_crypt_t *encrypter; 
    794773    } encrypted_arg_t; 
    795  
    796  
    797 /* dummy function */ 
    798774 
    799775#ifndef ATTRIBUTE_UNUSED 
     
    801777#endif /* ATTRIBUTE_UNUSED */ 
    802778 
    803 void ops_write_pk_session_key(ops_create_info_t *info ATTRIBUTE_UNUSED, ops_pk_session_key_t *session_key ATTRIBUTE_UNUSED) 
    804     { 
    805     /* \todo write ops_write_pk_session_key() */ 
     779ops_boolean_t ops_write_pk_session_key(ops_create_info_t *info, 
     780                                       ops_pk_session_key_t *pksk) 
     781    { 
     782    assert(pksk->algorithm == OPS_PKA_RSA); 
     783    return ops_write_ptag(OPS_PTAG_CT_PK_SESSION_KEY, info) 
     784        && ops_write_length(1 + 8 + 1 + BN_num_bytes(pksk->parameters.rsa.encrypted_m) + 2, info) 
     785        && ops_write_scalar(pksk->version, 1, info) 
     786        && ops_write(pksk->key_id, 8, info) 
     787        && ops_write_scalar(pksk->algorithm, 1, info) 
     788        && ops_write_mpi(pksk->parameters.rsa.encrypted_m, info) 
     789        /* XXX: write the checksum! */ 
     790        && ops_write_scalar(0, 2, info); 
     791    } 
     792 
     793static ops_boolean_t encrypted_writer(const unsigned char *src ATTRIBUTE_UNUSED, 
     794                                      unsigned length ATTRIBUTE_UNUSED, 
     795                                      ops_error_t **errors ATTRIBUTE_UNUSED, 
     796                                      ops_writer_info_t *winfo ATTRIBUTE_UNUSED) 
     797    { 
     798    /* \todo */ 
    806799    assert(0); 
    807     } 
    808  
    809 static ops_boolean_t encrypted_writer(const unsigned char *src ATTRIBUTE_UNUSED, 
    810                               unsigned length ATTRIBUTE_UNUSED, 
    811                               ops_error_t **errors ATTRIBUTE_UNUSED, 
    812                               ops_writer_info_t *winfo ATTRIBUTE_UNUSED 
    813                               ) 
    814     { 
    815      /* \todo */ 
    816     assert(0); 
    817800 
    818801    return ops_false; 
     
    820803 
    821804static ops_boolean_t encrypted_finaliser(ops_error_t **errors ATTRIBUTE_UNUSED, 
    822                                            ops_writer_info_t *winfo ATTRIBUTE_UNUSED) 
     805                                         ops_writer_info_t *winfo ATTRIBUTE_UNUSED) 
    823806    { 
    824807    /* \todo */ 
  • openpgpsdk/trunk/src/advanced/adv_crypto.c

    r462 r470  
    11#include <openpgpsdk/crypto.h> 
     2#include <openpgpsdk/random.h> 
    23 
    34#include <assert.h> 
     
    2829        return -1; 
    2930 
    30        /* 
     31    /* 
    3132    printf(" decrypt=%d ",n); 
    3233    hexdump(mpibuf,n); 
    3334    printf("\n"); 
    34        */ 
     35    */ 
    3536 
    3637    // Decode EME-PKCS1_V1_5 (RFC 2437). 
     
    5455    return n-i; 
    5556    } 
     57 
     58ops_boolean_t ops_encrypt_mpi(const unsigned char *buf, size_t buflen, 
     59                              const ops_public_key_t *pkey, 
     60                              ops_pk_session_key_parameters_t *skp) 
     61    { 
     62    unsigned char encmpibuf[8192]; 
     63    unsigned char padded[8192]; 
     64    int n; 
     65    unsigned i; 
     66 
     67    assert(pkey->algorithm == OPS_PKA_RSA); 
     68 
     69    n=BN_num_bytes(pkey->key.rsa.n); 
     70    padded[0]=0; 
     71    padded[1]=2; 
     72    // add non-zero random bytes 
     73    for(i=2 ; i < n-buflen-1 ; ++i) 
     74        do 
     75            ops_random(padded+i, 1); 
     76        while(padded[i] == 0); 
     77    padded[i++]=0; 
     78    memcpy(padded+i, buf, buflen); 
     79     
     80    n=ops_rsa_public_encrypt(encmpibuf, padded, n, &pkey->key.rsa); 
     81 
     82    if(n <= 0) 
     83        return ops_false; 
     84 
     85    skp->rsa.encrypted_m=BN_bin2bn(encmpibuf, n, NULL); 
     86 
     87    return ops_true; 
     88    } 
  • openpgpsdk/trunk/src/advanced/adv_openssl_crypto.c

    r426 r470  
    173173    } 
    174174 
     175int ops_rsa_public_encrypt(unsigned char *out,const unsigned char *in, 
     176                           size_t length,const ops_rsa_public_key_t *rsa) 
     177    { 
     178    RSA *orsa; 
     179    int n; 
     180 
     181    orsa=RSA_new(); 
     182    orsa->n=rsa->n; 
     183    orsa->e=rsa->e; 
     184 
     185    n=RSA_public_encrypt(length,in,out,orsa,RSA_NO_PADDING); 
     186 
     187    orsa->n=orsa->e=NULL; 
     188    RSA_free(orsa); 
     189 
     190    return n; 
     191    } 
     192 
    175193void ops_crypto_init() 
    176194    { 
  • openpgpsdk/trunk/src/advanced/adv_packet-parse.c

    r465 r470  
    18881888    ops_parser_content_t content; 
    18891889    unsigned char c[1]; 
    1890     ops_decrypt_t decrypt; 
     1890    ops_crypt_t decrypt; 
    18911891    int ret=1; 
    18921892    ops_region_t encregion; 
     
    20412041        free(passphrase); 
    20422042 
    2043         ops_decrypt_any(&decrypt,C.secret_key.algorithm); 
     2043        ops_crypt_any(&decrypt,C.secret_key.algorithm); 
    20442044        decrypt.set_iv(&decrypt,C.secret_key.iv); 
    20452045        decrypt.set_key(&decrypt,key); 
     
    22382238    CBP(pinfo,OPS_PTAG_CT_PK_SESSION_KEY,&content); 
    22392239 
    2240     ops_decrypt_any(&pinfo->decrypt,C.pk_session_key.symmetric_algorithm); 
     2240    ops_crypt_any(&pinfo->decrypt,C.pk_session_key.symmetric_algorithm); 
    22412241    pinfo->decrypt.set_key(&pinfo->decrypt,C.pk_session_key.key); 
    22422242 
     
    22492249    { 
    22502250    int r=1; 
    2251     ops_decrypt_t *decrypt=ops_parse_get_decrypt(pinfo); 
     2251    ops_crypt_t *decrypt=ops_parse_get_decrypt(pinfo); 
    22522252 
    22532253    if(decrypt) 
     
    22762276        if(tag == OPS_PTAG_CT_SE_DATA_BODY) 
    22772277            { 
    2278             decrypt->resync(decrypt); 
     2278            decrypt->decrypt_resync(decrypt); 
    22792279            decrypt->block_encrypt(decrypt,decrypt->civ,decrypt->civ); 
    22802280            } 
     
    27522752    { return pinfo->errors; } 
    27532753 
    2754 ops_decrypt_t *ops_parse_get_decrypt(ops_parse_info_t *pinfo) 
     2754ops_crypt_t *ops_parse_get_decrypt(ops_parse_info_t *pinfo) 
    27552755    { 
    27562756    if(pinfo->decrypt.algorithm) 
  • openpgpsdk/trunk/src/advanced/adv_symmetric.c

    r457 r470  
    1717    size_t decrypted_count; 
    1818    size_t decrypted_offset; 
    19     ops_decrypt_t *decrypt; 
     19    ops_crypt_t *decrypt; 
    2020    ops_region_t *region; 
    2121    ops_boolean_t prev_read_was_plain:1; 
     
    3333        { 
    3434        assert(rinfo->pinfo->reading_v3_secret); 
    35         arg->decrypt->resync(arg->decrypt); 
     35        arg->decrypt->decrypt_resync(arg->decrypt); 
    3636        arg->prev_read_was_plain=ops_false; 
    3737        } 
     
    9494            if(!rinfo->pinfo->reading_v3_secret 
    9595               || !rinfo->pinfo->reading_mpi_length) 
    96                 arg->decrypted_count=ops_decrypt_decrypt(arg->decrypt, 
    97                                                         arg->decrypted, 
    98                                                         buffer,n); 
     96                arg->decrypted_count=ops_decrypt(arg->decrypt, 
     97                                                arg->decrypted, 
     98                                                buffer,n); 
    9999            else 
    100100                { 
     
    115115    { free(ops_reader_get_arg(rinfo)); } 
    116116 
    117 void ops_reader_push_decrypt(ops_parse_info_t *pinfo,ops_decrypt_t *decrypt, 
     117void ops_reader_push_decrypt(ops_parse_info_t *pinfo,ops_crypt_t *decrypt, 
    118118                             ops_region_t *region) 
    119119    { 
     
    132132    encrypted_arg_t *arg=ops_reader_get_arg(ops_parse_get_rinfo(pinfo)); 
    133133 
    134     arg->decrypt->finish(arg->decrypt); 
     134    arg->decrypt->decrypt_finish(arg->decrypt); 
    135135    free(arg); 
    136136     
     
    138138    } 
    139139 
    140 static void std_set_iv(ops_decrypt_t *decrypt,const unsigned char *iv) 
    141     { memcpy(decrypt->iv,iv,decrypt->blocksize); } 
    142  
    143 static void std_set_key(ops_decrypt_t *decrypt,const unsigned char *key) 
    144     { memcpy(decrypt->key,key,decrypt->keysize); } 
    145  
    146 static void std_resync(ops_decrypt_t *decrypt) 
     140static void std_set_iv(ops_crypt_t *crypt,const unsigned char *iv) 
     141    { memcpy(crypt->iv,iv,crypt->blocksize); } 
     142 
     143static void std_set_key(ops_crypt_t *crypt,const unsigned char *key) 
     144    { memcpy(crypt->key,key,crypt->keysize); } 
     145 
     146static void std_resync(ops_crypt_t *decrypt) 
    147147    { 
    148148    if(decrypt->num == decrypt->blocksize) 
     
    156156    } 
    157157 
    158 static void std_finish(ops_decrypt_t *decrypt) 
    159     { 
    160     free(decrypt->data); 
    161     decrypt->data=NULL; 
    162     } 
    163  
    164 static void cast5_init(ops_decrypt_t *decrypt) 
    165     { 
    166     free(decrypt->data); 
    167     decrypt->data=malloc(sizeof(CAST_KEY)); 
    168     CAST_set_key(decrypt->data,decrypt->keysize,decrypt->key); 
    169     } 
    170  
    171 static void cast5_encrypt(ops_decrypt_t *decrypt,void *out,const void *in) 
    172     { CAST_ecb_encrypt(in,out,decrypt->data,1); } 
     158static void std_finish(ops_crypt_t *crypt) 
     159    { 
     160    free(crypt->data); 
     161    crypt->data=NULL; 
     162    } 
     163 
     164static void cast5_init(ops_crypt_t *crypt) 
     165    { 
     166    free(crypt->data); 
     167    crypt->data=malloc(sizeof(CAST_KEY)); 
     168    CAST_set_key(crypt->data,crypt->keysize,crypt->key); 
     169    } 
     170 
     171static void cast5_encrypt(ops_crypt_t *crypt,void *out,const void *in) 
     172    { CAST_ecb_encrypt(in,out,crypt->data,1); } 
    173173 
    174174#define TRAILER         "","","","",0,NULL 
    175175 
    176 static ops_decrypt_t cast5= 
     176static ops_crypt_t cast5= 
    177177    { 
    178178    OPS_SA_CAST5, 
     
    189189 
    190190#ifndef OPENSSL_NO_IDEA 
    191 static void idea_init(ops_decrypt_t *decrypt) 
    192     { 
    193     assert(decrypt->keysize == IDEA_KEY_LENGTH); 
    194  
    195     free(decrypt->data); 
    196     decrypt->data=malloc(sizeof(IDEA_KEY_SCHEDULE)); 
    197  
    198     // note that we don't invert the key for CFB mode 
    199     idea_set_encrypt_key(decrypt->key,decrypt->data); 
    200     } 
    201  
    202 static void idea_block_encrypt(ops_decrypt_t *decrypt,void *out,const void *in) 
    203     { idea_ecb_encrypt(in,out,decrypt->data); } 
    204  
    205 static const ops_decrypt_t idea= 
     191static void idea_init(ops_crypt_t *crypt) 
     192    { 
     193    assert(crypt->keysize == IDEA_KEY_LENGTH); 
     194 
     195    free(crypt->data); 
     196    crypt->data=malloc(sizeof(IDEA_KEY_SCHEDULE)); 
     197 
     198    // note that we don't invert the key when decrypting for CFB mode 
     199    idea_set_encrypt_key(crypt->key,crypt->data); 
     200    } 
     201 
     202static void idea_block_encrypt(ops_crypt_t *crypt,void *out,const void *in) 
     203    { idea_ecb_encrypt(in,out,crypt->data); } 
     204 
     205static const ops_crypt_t idea= 
    206206    { 
    207207    OPS_SA_IDEA, 
     
    218218#endif /* OPENSSL_NO_IDEA */ 
    219219 
    220 static void aes256_init(ops_decrypt_t *decrypt) 
    221     { 
    222     free(decrypt->data); 
    223     decrypt->data=malloc(sizeof(AES_KEY)); 
    224     AES_set_encrypt_key(decrypt->key,256,decrypt->data); 
    225     } 
    226  
    227 static void aes_block_encrypt(ops_decrypt_t *decrypt,void *out,const void *in) 
    228     { AES_encrypt(in,out,decrypt->data); } 
    229  
    230 static const ops_decrypt_t aes256= 
     220static void aes256_init(ops_crypt_t *crypt) 
     221    { 
     222    free(crypt->data); 
     223    crypt->data=malloc(sizeof(AES_KEY)); 
     224    AES_set_encrypt_key(crypt->key,256,crypt->data); 
     225    } 
     226 
     227static void aes_block_encrypt(ops_crypt_t *crypt,void *out,const void *in) 
     228    { AES_encrypt(in,out,crypt->data); } 
     229 
     230static const ops_crypt_t aes256= 
    231231    { 
    232232    OPS_SA_AES_256, 
     
    242242    }; 
    243243 
    244 static void tripledes_init(ops_decrypt_t *decrypt) 
     244static void tripledes_init(ops_crypt_t *crypt) 
    245245    { 
    246246    DES_key_schedule *keys; 
    247247    int n; 
    248248 
    249     free(decrypt->data); 
    250     keys=decrypt->data=malloc(3*sizeof(DES_key_schedule)); 
     249    free(crypt->data); 
     250    keys=crypt->data=malloc(3*sizeof(DES_key_schedule)); 
    251251 
    252252    for(n=0 ; n < 3 ; ++n) 
    253         DES_set_key((DES_cblock *)(decrypt->key+n*8),&keys[n]); 
    254     } 
    255  
    256 static void tripledes_block_encrypt(ops_decrypt_t *decrypt,void *out, 
     253        DES_set_key((DES_cblock *)(crypt->key+n*8),&keys[n]); 
     254    } 
     255 
     256static void tripledes_block_encrypt(ops_crypt_t *crypt,void *out, 
    257257                                    const void *in) 
    258258    { 
    259     DES_key_schedule *keys=decrypt->data; 
     259    DES_key_schedule *keys=crypt->data; 
    260260 
    261261    DES_ecb3_encrypt((void *)in,out,&keys[0],&keys[1],&keys[2],1); 
    262262    } 
    263263 
    264 static const ops_decrypt_t tripledes= 
     264static const ops_crypt_t tripledes= 
    265265    { 
    266266    OPS_SA_TRIPLEDES, 
     
    276276    }; 
    277277 
    278 static const ops_decrypt_t *get_proto(ops_symmetric_algorithm_t alg) 
     278static const ops_crypt_t *get_proto(ops_symmetric_algorithm_t alg) 
    279279    { 
    280280    switch(alg) 
     
    303303    } 
    304304 
    305 void ops_decrypt_any(ops_decrypt_t *decrypt,ops_symmetric_algorithm_t alg) 
    306     { *decrypt=*get_proto(alg); } 
     305void ops_crypt_any(ops_crypt_t *crypt,ops_symmetric_algorithm_t alg) 
     306    { *crypt=*get_proto(alg); } 
    307307 
    308308unsigned ops_block_size(ops_symmetric_algorithm_t alg) 
    309309    { 
    310     const ops_decrypt_t *p=get_proto(alg); 
     310    const ops_crypt_t *p=get_proto(alg); 
    311311 
    312312    if(!p) 
     
    318318unsigned ops_key_size(ops_symmetric_algorithm_t alg) 
    319319    { 
    320     const ops_decrypt_t *p=get_proto(alg); 
     320    const ops_crypt_t *p=get_proto(alg); 
    321321 
    322322    if(!p) 
     
    326326    } 
    327327 
    328 void ops_decrypt_init(ops_decrypt_t *decrypt) 
     328void ops_decrypt_init(ops_crypt_t *decrypt) 
    329329    { 
    330330    decrypt->base_init(decrypt); 
     
    334334    } 
    335335 
    336 size_t ops_decrypt_decrypt(ops_decrypt_t *decrypt,void *out_,const void *in_, 
    337                           size_t count) 
     336size_t ops_decrypt(ops_crypt_t *decrypt,void *out_,const void *in_, 
     337                   size_t count) 
    338338    { 
    339339    unsigned char *out=out_; 
     
    359359    return saved; 
    360360    } 
     361 
     362size_t ops_encrypt(ops_crypt_t *decrypt,void *out_,const void *in_, 
     363                   size_t count) 
     364    { 
     365    unsigned char *out=out_; 
     366    const unsigned char *in=in_; 
     367    int saved=count; 
     368 
     369    /* in order to support v3's weird resyncing we have to implement CFB mode 
     370       ourselves */ 
     371    while(count-- > 0) 
     372        { 
     373        if(decrypt->num == decrypt->blocksize) 
     374            { 
     375            memcpy(decrypt->siv,decrypt->civ,decrypt->blocksize); 
     376            decrypt->block_encrypt(decrypt,decrypt->civ,decrypt->civ); 
     377            decrypt->num=0; 
     378            } 
     379        decrypt->civ[decrypt->num]=*out++=decrypt->civ[decrypt->num]^*in++; 
     380        ++decrypt->num; 
     381        } 
     382 
     383    return saved; 
     384    } 
  • openpgpsdk/trunk/src/advanced/parse_local.h

    r426 r470  
    6969    ops_parse_cb_info_t cbinfo; 
    7070    ops_error_t *errors; 
    71     ops_decrypt_t decrypt; 
     71    ops_crypt_t decrypt; 
    7272    size_t nhashes; 
    7373    ops_parse_hash_info_t *hashes; 
  • openpgpsdk/trunk/tests/Makefile.template

    r468 r470  
    2626$(CUNIT_LIB): 
    2727        tar xvfz CUnit-2.1-0-src.tar.gz 
    28         (cd CUnit-2.1-0; ./configure --prefix $(PWD)/../; make; make install) 
     28        (cd CUnit-2.1-0 && ./configure --prefix $(PWD)/../ && make && make install) 
    2929 
    3030clean: