~ubuntu-branches/ubuntu/lucid/openssl/lucid-proposed

« back to all changes in this revision

Viewing changes to crypto/rsa/rsa_eay.c

  • Committer: Bazaar Package Importer
  • Author(s): Nicolas Valcárcel Scerpella (Canonical)
  • Date: 2009-12-06 20:16:24 UTC
  • mfrom: (11.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20091206201624-u126qjpqm2n2uuhu
Tags: 0.9.8k-7ubuntu1
* Merge from debian unstable, remaining changes (LP: #493392):
  - Link using -Bsymbolic-functions
  - Add support for lpia
  - Disable SSLv2 during compile
  - Ship documentation in openssl-doc, suggested by the package.
  - Use a different priority for libssl0.9.8/restart-services
    depending on whether a desktop, or server dist-upgrade is being
    performed.
  - Display a system restart required notification bubble on libssl0.9.8
    upgrade.
  - Replace duplicate files in the doc directory with symlinks.
  - Move runtime libraries to /lib, for the benefit of wpasupplicant
* Strip the patches out of the source into quilt patches
* Disable CVE-2009-3555.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
115
115
#include <openssl/rsa.h>
116
116
#include <openssl/rand.h>
117
117
 
118
 
#ifndef RSA_NULL
 
118
#if !defined(RSA_NULL) && !defined(OPENSSL_FIPS)
119
119
 
120
120
static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
121
121
                unsigned char *to, RSA *rsa,int padding);
150
150
        return(&rsa_pkcs1_eay_meth);
151
151
        }
152
152
 
153
 
/* Usage example;
154
 
 *    MONT_HELPER(rsa, bn_ctx, p, rsa->flags & RSA_FLAG_CACHE_PRIVATE, goto err);
155
 
 */
156
 
#define MONT_HELPER(rsa, ctx, m, pre_cond, err_instr) \
157
 
        if((pre_cond) && ((rsa)->_method_mod_##m == NULL) && \
158
 
                        !BN_MONT_CTX_set_locked(&((rsa)->_method_mod_##m), \
159
 
                                CRYPTO_LOCK_RSA, \
160
 
                                (rsa)->m, (ctx))) \
161
 
                err_instr
162
 
 
163
153
static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
164
154
             unsigned char *to, RSA *rsa, int padding)
165
155
        {
227
217
        if (BN_bin2bn(buf,num,f) == NULL) goto err;
228
218
        
229
219
        if (BN_ucmp(f, rsa->n) >= 0)
230
 
                {       
 
220
                {
231
221
                /* usually the padding functions would catch this */
232
222
                RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
233
223
                goto err;
234
224
                }
235
225
 
236
 
        MONT_HELPER(rsa, ctx, n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err);
 
226
        if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
 
227
                if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx))
 
228
                        goto err;
237
229
 
238
230
        if (!rsa->meth->bn_mod_exp(ret,f,rsa->e,rsa->n,ctx,
239
231
                rsa->_method_mod_n)) goto err;
436
428
                        BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);
437
429
                        }
438
430
                else
439
 
                        d = rsa->d;
 
431
                        d= rsa->d;
440
432
 
441
 
                MONT_HELPER(rsa, ctx, n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err);
 
433
                if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
 
434
                        if(!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx))
 
435
                                goto err;
442
436
 
443
437
                if (!rsa->meth->bn_mod_exp(ret,f,d,rsa->n,ctx,
444
438
                                rsa->_method_mod_n)) goto err;
559
553
                else
560
554
                        d = rsa->d;
561
555
 
562
 
                MONT_HELPER(rsa, ctx, n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err);
 
556
                if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
 
557
                        if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx))
 
558
                                goto err;
563
559
                if (!rsa->meth->bn_mod_exp(ret,f,d,rsa->n,ctx,
564
560
                                rsa->_method_mod_n))
565
561
                  goto err;
669
665
                goto err;
670
666
                }
671
667
 
672
 
        MONT_HELPER(rsa, ctx, n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err);
 
668
        if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
 
669
                if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx))
 
670
                        goto err;
673
671
 
674
672
        if (!rsa->meth->bn_mod_exp(ret,f,rsa->e,rsa->n,ctx,
675
673
                rsa->_method_mod_n)) goto err;
717
715
        BIGNUM *r1,*m1,*vrfy;
718
716
        BIGNUM local_dmp1,local_dmq1,local_c,local_r1;
719
717
        BIGNUM *dmp1,*dmq1,*c,*pr1;
720
 
        int bn_flags;
721
718
        int ret=0;
722
719
 
723
720
        BN_CTX_start(ctx);
725
722
        m1 = BN_CTX_get(ctx);
726
723
        vrfy = BN_CTX_get(ctx);
727
724
 
728
 
        /* Make sure mod_inverse in montgomerey intialization use correct 
729
 
         * BN_FLG_CONSTTIME flag.
730
 
         */
731
 
        bn_flags = rsa->p->flags;
732
 
        if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
733
 
                {
734
 
                rsa->p->flags |= BN_FLG_CONSTTIME;
735
 
                }
736
 
        MONT_HELPER(rsa, ctx, p, rsa->flags & RSA_FLAG_CACHE_PRIVATE, goto err);
737
 
        /* We restore bn_flags back */
738
 
        rsa->p->flags = bn_flags;
739
 
 
740
 
        /* Make sure mod_inverse in montgomerey intialization use correct
741
 
         * BN_FLG_CONSTTIME flag.
742
 
         */
743
 
        bn_flags = rsa->q->flags;
744
 
        if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
745
 
                {
746
 
                rsa->q->flags |= BN_FLG_CONSTTIME;
747
 
                }
748
 
        MONT_HELPER(rsa, ctx, q, rsa->flags & RSA_FLAG_CACHE_PRIVATE, goto err);
749
 
        /* We restore bn_flags back */
750
 
        rsa->q->flags = bn_flags;       
751
 
 
752
 
        MONT_HELPER(rsa, ctx, n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err);
 
725
        {
 
726
                BIGNUM local_p, local_q;
 
727
                BIGNUM *p = NULL, *q = NULL;
 
728
 
 
729
                /* Make sure BN_mod_inverse in Montgomery intialization uses the
 
730
                 * BN_FLG_CONSTTIME flag (unless RSA_FLAG_NO_CONSTTIME is set)
 
731
                 */
 
732
                if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
 
733
                        {
 
734
                        BN_init(&local_p);
 
735
                        p = &local_p;
 
736
                        BN_with_flags(p, rsa->p, BN_FLG_CONSTTIME);
 
737
 
 
738
                        BN_init(&local_q);
 
739
                        q = &local_q;
 
740
                        BN_with_flags(q, rsa->q, BN_FLG_CONSTTIME);
 
741
                        }
 
742
                else
 
743
                        {
 
744
                        p = rsa->p;
 
745
                        q = rsa->q;
 
746
                        }
 
747
 
 
748
                if (rsa->flags & RSA_FLAG_CACHE_PRIVATE)
 
749
                        {
 
750
                        if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_p, CRYPTO_LOCK_RSA, p, ctx))
 
751
                                goto err;
 
752
                        if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_q, CRYPTO_LOCK_RSA, q, ctx))
 
753
                                goto err;
 
754
                        }
 
755
        }
 
756
 
 
757
        if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
 
758
                if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx))
 
759
                        goto err;
753
760
 
754
761
        /* compute I mod q */
755
762
        if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))