updates. New data types.
[silc.git] / lib / silccrypt / pkcs1.c
index 8420b8b100416359a287d395e68fa0ca703574fc..a6a68146c08dd3c8e8a73cc2d7daffb1fece9b01 100644 (file)
@@ -33,9 +33,9 @@
                ftp://ftp.rsasecurity.com/pub/pkcs/ascii/pkcs-1.asc,
               and RFC 2437.
 
-   Copyright notice: All code, including the SILC PKCS API code that is
-   not part of the Mozilla code, falls under the same license (MPL or GPL)
-   found attached to this file, below.
+   Copyright notice: All code in this file, including the SILC PKCS API
+   code that is not part of the Mozilla code, falls under the same license
+   (MPL or GPL) found attached to this file, below.
 */
 
 /*
@@ -104,12 +104,13 @@ typedef enum {
  * the rules defined in PKCS #1.
  */
 static unsigned char *
-RSA_FormatOneBlock(unsigned int modulusLen, RSA_BlockType blockType,
-                  unsigned char *data, unsigned int data_len)
+RSA_FormatOneBlock(uint32 modulusLen, RSA_BlockType blockType,
+                  unsigned char *data, uint32 data_len)
 {
     unsigned char *block;
     unsigned char *bp;
     int padLen;
+    int i;
 
     block = (unsigned char *) silc_malloc(modulusLen);
     if (block == NULL)
@@ -152,15 +153,6 @@ RSA_FormatOneBlock(unsigned int modulusLen, RSA_BlockType blockType,
        * Blocks intended for public-key operation.
        */
       case RSA_BlockPublic:
-
-       /* XXX For now we can't do this because we can't get the
-          SilcRNG object down to this level. */
-       silc_free(block);
-       return NULL;
-
-#if 0
-       int i;
-
        /*
         * 0x00 || BT || Pad || 0x00 || ActualData
         *   1      1   padLen    1      data_len
@@ -171,14 +163,12 @@ RSA_FormatOneBlock(unsigned int modulusLen, RSA_BlockType blockType,
        for (i = 0; i < padLen; i++) {
            /* Pad with non-zero random data. */
            do {
-               RNG_GenerateGlobalRandomBytes(bp + i, 1);
+               silc_rng_global_get_byte(bp + i);
            } while (bp[i] == RSA_BLOCK_AFTER_PAD_OCTET);
        }
        bp += padLen;
        *bp++ = RSA_BLOCK_AFTER_PAD_OCTET;
        memcpy(bp, data, data_len);
-#endif
-
        break;
 
       default:
@@ -190,10 +180,10 @@ RSA_FormatOneBlock(unsigned int modulusLen, RSA_BlockType blockType,
 }
 
 static int
-RSA_FormatBlock(unsigned char **result, unsigned int *result_len,
-               unsigned int modulusLen,
+RSA_FormatBlock(unsigned char **result, uint32 *result_len,
+               uint32 modulusLen,
                RSA_BlockType blockType, unsigned char *data,
-               unsigned int data_len)
+               uint32 data_len)
 {
     /*
      * XXX For now assume that the data length fits in a single
@@ -247,14 +237,14 @@ RSA_FormatBlock(unsigned char **result, unsigned int *result_len,
  */
 unsigned char *
 RSA_DecodeOneBlock(unsigned char *data,
-                  unsigned int modulusLen,
-                  unsigned int expectedLen,
+                  uint32 modulusLen,
+                  uint32 expectedLen,
                   RSA_BlockType bt,
-                  unsigned int *pResultLen)
+                  uint32 *pResultLen)
 {
     RSA_BlockType blockType;
     unsigned char *dp, *res;
-    unsigned int i, len = 0;
+    uint32 i, len = 0;
 
     dp = data;
     if (dp[0] != RSA_BLOCK_FIRST_OCTET) {
@@ -326,7 +316,7 @@ SILC_PKCS_API_ENCRYPT(pkcs1)
   SilcInt mp_tmp;
   SilcInt mp_dst;
   unsigned char *padded;
-  unsigned int padded_len, len = key->bits / 8;
+  uint32 padded_len, len = key->bits / 8;
 
   /* Pad data */
   if (!RSA_FormatBlock(&padded, &padded_len, len,
@@ -360,7 +350,7 @@ SILC_PKCS_API_DECRYPT(pkcs1)
   SilcInt mp_tmp;
   SilcInt mp_dst;
   unsigned char *padded, *unpadded;
-  unsigned int padded_len;
+  uint32 padded_len;
 
   silc_mp_init_set_ui(&mp_tmp, 0);
   silc_mp_init_set_ui(&mp_dst, 0);
@@ -405,8 +395,8 @@ SILC_PKCS_API_SIGN(pkcs1)
   SilcInt mp_tmp;
   SilcInt mp_dst;
   unsigned char *padded;
-  unsigned int padded_len;
-  unsigned int len = key->bits / 8;
+  uint32 padded_len;
+  uint32 len = key->bits / 8;
 
   /* Pad data */
   if (!RSA_FormatBlock(&padded, &padded_len, len, RSA_BlockPrivate, 
@@ -441,7 +431,7 @@ SILC_PKCS_API_VERIFY(pkcs1)
   SilcInt mp_tmp2;
   SilcInt mp_dst;
   unsigned char *verify, *unpadded;
-  unsigned int verify_len, len = key->bits / 8;
+  uint32 verify_len, len = key->bits / 8;
 
   silc_mp_init_set_ui(&mp_tmp2, 0);
   silc_mp_init_set_ui(&mp_dst, 0);