Changeset 333

Show
Ignore:
Timestamp:
01/20/06 09:02:19
Author:
ben
Message:

Beginnings of decryption.

Files:

Legend:

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

    r323 r333  
    88LIBS=$(LIBDEPS) %CRYPTO_LIBS% %ZLIB% $(DM_LIB) %LIBS% 
    99EXES=packet-dump verify create-key create-signed-key verify2 sign-detached \ 
    10      sign-inline 
     10     sign-inline decrypt 
    1111 
    1212all: Makefile .depend $(EXES) 
     
    3737sign-inline: sign-inline.o $(LIBDEPS) 
    3838        $(CC) $(LDFLAGS) -o sign-inline sign-inline.o $(LIBS) 
     39 
     40decrypt: decrypt.o $(LIBPDEPS) 
     41        $(CC) $(LDFLAGS) -o decrypt decrypt.o $(LIBS) 
     42 
    3943 
    4044tags: 
  • openpgpsdk/trunk/include/openpgpsdk/crypto.h

    r314 r333  
    4646                            const ops_rsa_public_key_t *rsa); 
    4747 
     48unsigned ops_block_size(ops_symmetric_algorithm_t alg); 
     49 
    4850#endif 
  • openpgpsdk/trunk/include/openpgpsdk/packet.h

    r326 r333  
    344344typedef enum 
    345345    { 
    346     OPS_S2K_NONE=0, 
     346    OPS_S2KU_NONE=0, 
     347    OPS_S2KU_ENCRYPTED_AND_HASHED=254, 
     348    OPS_S2KU_ENCRYPTED=255 
    347349    } ops_s2k_usage_t; 
     350 
     351/** s2k_specifier_t 
     352 */ 
     353typedef enum 
     354    { 
     355    OPS_S2KS_SIMPLE=0, 
     356    OPS_S2KS_SALTED=1, 
     357    OPS_S2KS_ITERATED_AND_SALTED=3 
     358    } ops_s2k_specifier_t; 
     359 
     360/** Symmetric Key Algorithm Numbers. 
     361 * OpenPGP assigns a unique Algorithm Number to each algorithm that is part of OpenPGP. 
     362 * 
     363 * This lists algorithm numbers for symmetric key algorithms. 
     364 *  
     365 * \see RFC2440bis-12 9.2 
     366 */ 
     367typedef enum 
     368    { 
     369    OPS_SA_PLAINTEXT    =0, /*!< Plaintext or unencrypted data */ 
     370    OPS_SA_IDEA         =1, /*!< IDEA */ 
     371    OPS_SA_TRIPLEDES    =2, /*!< TripleDES */ 
     372    OPS_SA_CAST5        =3, /*!< CAST5 */ 
     373    OPS_SA_BLOWFISH     =4, /*!< Blowfish */ 
     374    OPS_SA_AES_128      =7, /*!< AES with 128-bit key (AES) */ 
     375    OPS_SA_AES_192      =8, /*!< AES with 192-bit key */ 
     376    OPS_SA_AES_256      =9, /*!< AES with 256-bit key */ 
     377    OPS_SA_TWOFISH      =10, /*!< Twofish with 256-bit key (TWOFISH) */ 
     378    } ops_symmetric_algorithm_t; 
     379 
     380// Maximum block size for symmetric crypto 
     381#define OPS_MAX_BLOCK_SIZE      16 
    348382 
    349383/** ops_secret_key_t 
     
    353387    ops_public_key_t            public_key; 
    354388    ops_s2k_usage_t             s2k_usage; 
     389    ops_symmetric_algorithm_t   algorithm; 
     390    unsigned char               iv[OPS_MAX_BLOCK_SIZE]; 
    355391    unsigned                    checksum; 
    356392    ops_secret_key_union_t      key; 
    357393    } ops_secret_key_t; 
    358  
    359 /** Symmetric Key Algorithm Numbers. 
    360  * OpenPGP assigns a unique Algorithm Number to each algorithm that is part of OpenPGP. 
    361  * 
    362  * This lists algorithm numbers for symmetric key algorithms. 
    363  *  
    364  * \see RFC2440bis-12 9.2 
    365  */ 
    366 typedef enum 
    367     { 
    368     OPS_SKA_PLAINTEXT   =0, /*!< Plaintext or unencrypted data */ 
    369     OPS_SKA_IDEA        =1, /*!< IDEA */ 
    370     OPS_SKA_TRIPLEDES   =2, /*!< TripleDES */ 
    371     OPS_SKA_CAST5       =3, /*!< CAST5 */ 
    372     OPS_SKA_BLOWFISH    =4, /*!< Blowfish */ 
    373     OPS_SKA_AES_128     =7, /*!< AES with 128-bit key (AES) */ 
    374     OPS_SKA_AES_192     =8, /*!< AES with 192-bit key */ 
    375     OPS_SKA_AES_256     =9, /*!< AES with 256-bit key */ 
    376     OPS_SKA_TWOFISH     =10, /*!< Twofish with 256-bit key (TWOFISH) */ 
    377  
    378     } ops_symmetric_key_algorithm_t; 
    379394 
    380395/** Structure to hold one trust packet's data */ 
  • openpgpsdk/trunk/src/Makefile.template

    r323 r333  
    1111LIBOBJS = packet-parse.o util.o openssl_crypto.o accumulate.o \ 
    1212        memory.o fingerprint.o hash.o keyring.o signature.o compress.o \ 
    13         packet-show.o create.o validate.o lists.o armour.o errors.o 
     13        packet-show.o create.o validate.o lists.o armour.o errors.o \ 
     14        symmetric.o 
    1415 
    1516headers: 
  • openpgpsdk/trunk/src/create.c

    r320 r333  
    327327     
    328328    // XXX: for now, no secret key encryption, so s2k == 0 
    329     assert(key->s2k_usage == OPS_S2K_NONE); 
     329    assert(key->s2k_usage == OPS_S2KU_NONE); 
    330330 
    331331    push_secret_key_checksum_writer(info); 
     
    466466    key->key.rsa.u=u; 
    467467 
    468     key->s2k_usage=OPS_S2K_NONE; 
     468    key->s2k_usage=OPS_S2KU_NONE; 
    469469 
    470470    // XXX: sanity check and add errors... 
  • openpgpsdk/trunk/src/packet-parse.c

    r326 r333  
    17531753        return 0; 
    17541754    C.secret_key.s2k_usage=c[0]; 
    1755     assert(C.secret_key.s2k_usage == OPS_S2K_NONE); 
     1755    if(C.secret_key.s2k_usage != OPS_S2KU_NONE) 
     1756        { 
     1757        int n; 
     1758 
     1759        assert(C.secret_key.s2k_usage == OPS_S2KU_ENCRYPTED 
     1760               || C.secret_key.s2k_usage == OPS_S2KU_ENCRYPTED_AND_HASHED); 
     1761 
     1762        if(!limited_read(c,1,region,parse_info)) 
     1763            return 0; 
     1764        C.secret_key.algorithm=c[0]; 
     1765 
     1766        n=ops_block_size(C.secret_key.algorithm); 
     1767        assert(n > 0 && n <= OPS_MAX_BLOCK_SIZE); 
     1768 
     1769        if(!limited_read(C.secret_key.iv,n,region,parse_info)) 
     1770            return 0; 
     1771        } 
    17561772 
    17571773    switch(C.secret_key.public_key.algorithm) 
  • openpgpsdk/trunk/src/packet-show.c

    r293 r333  
    129129static ops_map_t symmetric_key_algorithm_map[] = 
    130130    { 
    131     { OPS_SKA_PLAINTEXT,      "Plaintext or unencrypted data" }, 
    132     { OPS_SKA_IDEA,           "IDEA" }, 
    133     { OPS_SKA_TRIPLEDES,      "TripleDES" }, 
    134     { OPS_SKA_CAST5,          "CAST5" }, 
    135     { OPS_SKA_BLOWFISH,               "Blowfish" }, 
    136     { OPS_SKA_AES_128,                "AES(128-bit key)" }, 
    137     { OPS_SKA_AES_192,                "AES(192-bit key)" }, 
    138     { OPS_SKA_AES_256,                "AES(256-bit key)" }, 
    139     { OPS_SKA_TWOFISH,                "Twofish(256-bit key)" }, 
     131    { OPS_SA_PLAINTEXT,               "Plaintext or unencrypted data" }, 
     132    { OPS_SA_IDEA,            "IDEA" }, 
     133    { OPS_SA_TRIPLEDES,               "TripleDES" }, 
     134    { OPS_SA_CAST5,           "CAST5" }, 
     135    { OPS_SA_BLOWFISH,                "Blowfish" }, 
     136    { OPS_SA_AES_128,         "AES(128-bit key)" }, 
     137    { OPS_SA_AES_192,         "AES(192-bit key)" }, 
     138    { OPS_SA_AES_256,                 "AES(256-bit key)" }, 
     139    { OPS_SA_TWOFISH,                 "Twofish(256-bit key)" }, 
    140140    { (int) NULL,               (char *)NULL }, /* this is the end-of-array marker */ 
    141141    };