Ticket #8792: 0001-Remove-PK_PKCS1_PADDING.patch

File 0001-Remove-PK_PKCS1_PADDING.patch, 3.1 KB (added by arlolra, 6 years ago)
  • src/common/crypto.c

    From 51d81ac3a8b44bc00cb47b10e4ffac8e0c2f0a3b Mon Sep 17 00:00:00 2001
    From: Arlo Breault <arlolra@gmail.com>
    Date: Thu, 16 May 2013 12:05:50 -0700
    Subject: [PATCH] Remove PK_PKCS1_PADDING
    
    See #8792
    ---
     src/common/crypto.c    |  2 --
     src/common/crypto.h    |  4 ----
     src/test/test_crypto.c | 25 +++++++++++--------------
     3 files changed, 11 insertions(+), 20 deletions(-)
    
    diff --git a/src/common/crypto.c b/src/common/crypto.c
    index 31a0df1..bda1ed0 100644
    a b crypto_get_rsa_padding_overhead(int padding) 
    114114  switch (padding)
    115115    {
    116116    case RSA_PKCS1_OAEP_PADDING: return PKCS1_OAEP_PADDING_OVERHEAD;
    117     case RSA_PKCS1_PADDING: return PKCS1_PADDING_OVERHEAD;
    118117    default: tor_assert(0); return -1;
    119118    }
    120119}
    crypto_get_rsa_padding(int padding) 
    126125{
    127126  switch (padding)
    128127    {
    129     case PK_PKCS1_PADDING: return RSA_PKCS1_PADDING;
    130128    case PK_PKCS1_OAEP_PADDING: return RSA_PKCS1_OAEP_PADDING;
    131129    default: tor_assert(0); return -1;
    132130    }
  • src/common/crypto.h

    diff --git a/src/common/crypto.h b/src/common/crypto.h
    index 38eb455..2886306 100644
    a b  
    6969 * signs removed. */
    7070#define BASE64_DIGEST256_LEN 43
    7171
    72 /** Constant used to indicate PKCS1 padding for public-key encryption */
    73 #define PK_PKCS1_PADDING      60001
    7472/** Constant used to indicate OAEP padding for public-key encryption */
    7573#define PK_PKCS1_OAEP_PADDING 60002
    7674
    77 /** Number of bytes added for PKCS1 padding. */
    78 #define PKCS1_PADDING_OVERHEAD 11
    7975/** Number of bytes added for PKCS1-OAEP padding. */
    8076#define PKCS1_OAEP_PADDING_OVERHEAD 42
    8177
  • src/test/test_crypto.c

    diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c
    index 4b7e7f2..839de7d 100644
    a b test_crypto_pk(void) 
    394394  char *encoded = NULL;
    395395  char data1[1024], data2[1024], data3[1024];
    396396  size_t size;
    397   int i, j, p, len;
     397  int i, len;
    398398
    399399  /* Public-key ciphers */
    400400  pk1 = pk_generate(0);
    test_crypto_pk(void) 
    478478
    479479  /* Try with hybrid encryption wrappers. */
    480480  crypto_rand(data1, 1024);
    481   for (i = 0; i < 2; ++i) {
    482     for (j = 85; j < 140; ++j) {
    483       memset(data2,0,1024);
    484       memset(data3,0,1024);
    485       p = (i==0)?PK_PKCS1_PADDING:PK_PKCS1_OAEP_PADDING;
    486       len = crypto_pk_public_hybrid_encrypt(pk1,data2,sizeof(data2),
    487                                             data1,j,p,0);
    488       test_assert(len>=0);
    489       len = crypto_pk_private_hybrid_decrypt(pk1,data3,sizeof(data3),
    490                                              data2,len,p,1);
    491       test_eq(len,j);
    492       test_memeq(data1,data3,j);
    493     }
     481  for (i = 85; i < 140; ++i) {
     482    memset(data2,0,1024);
     483    memset(data3,0,1024);
     484    len = crypto_pk_public_hybrid_encrypt(pk1,data2,sizeof(data2),
     485                                          data1,i,PK_PKCS1_OAEP_PADDING,0);
     486    test_assert(len>=0);
     487    len = crypto_pk_private_hybrid_decrypt(pk1,data3,sizeof(data3),
     488                                           data2,len,PK_PKCS1_OAEP_PADDING,1);
     489    test_eq(len,i);
     490    test_memeq(data1,data3,i);
    494491  }
    495492
    496493  /* Try copy_full */