Engage s390x assembler modules.
[openssl.git] / crypto / bn / bn_blind.c
index 40e742dbadd64e178c419684729bd91fafe2a8d6..e9b6173e24c4aeb2a7503584290fe89dcfe0303e 100644 (file)
@@ -1,6 +1,6 @@
 /* crypto/bn/bn_blind.c */
 /* ====================================================================
- * Copyright (c) 1998-2005 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2006 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -123,6 +123,8 @@ struct bn_blinding_st
        BIGNUM *mod; /* just a reference */
        unsigned long thread_id; /* added in OpenSSL 0.9.6j and 0.9.7b;
                                  * used only by crypto/rsa/rsa_eay.c, rsa_lib.c */
+       void *thread_idptr; /* added in OpenSSL 0.9.9;
+                            * used only by crypto/rsa/rsa_eay.c, rsa_lib.c */
        unsigned int  counter;
        unsigned long flags;
        BN_MONT_CTX *m_ctx;
@@ -151,7 +153,12 @@ BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod)
                {
                if ((ret->Ai = BN_dup(Ai)) == NULL) goto err;
                }
-       ret->mod = mod;
+
+       /* save a copy of mod in the BN_BLINDING structure */
+       if ((ret->mod = BN_dup(mod)) == NULL) goto err;
+       if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)
+               BN_set_flags(ret->mod, BN_FLG_CONSTTIME);
+
        ret->counter = BN_BLINDING_COUNTER;
        return(ret);
 err:
@@ -167,6 +174,7 @@ void BN_BLINDING_free(BN_BLINDING *r)
        if (r->A  != NULL) BN_free(r->A );
        if (r->Ai != NULL) BN_free(r->Ai);
        if (r->e  != NULL) BN_free(r->e );
+       if (r->mod != NULL) BN_free(r->mod); 
        OPENSSL_free(r);
        }
 
@@ -207,6 +215,8 @@ int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx)
 
 int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *ctx)
        {
+       int ret = 1;
+
        bn_check_top(n);
 
        if ((b->A == NULL) || (b->Ai == NULL))
@@ -216,9 +226,13 @@ int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *ctx)
                }
 
        if (r != NULL)
-               BN_copy(r, b->Ai);
+               {
+               if (!BN_copy(r, b->Ai)) ret=0;
+               }
 
-       return BN_mod_mul(n,n,b->A,b->mod,ctx);
+       if (!BN_mod_mul(n,n,b->A,b->mod,ctx)) ret=0;
+       
+       return ret;
        }
 
 int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx)
@@ -261,6 +275,16 @@ void BN_BLINDING_set_thread_id(BN_BLINDING *b, unsigned long n)
        b->thread_id = n;
        }
 
+void *BN_BLINDING_get_thread_idptr(const BN_BLINDING *b)
+       {
+       return b->thread_idptr;
+       }
+
+void BN_BLINDING_set_thread_idptr(BN_BLINDING *b, void *p)
+       {
+       b->thread_idptr = p;
+       }
+
 unsigned long BN_BLINDING_get_flags(const BN_BLINDING *b)
        {
        return b->flags;
@@ -351,4 +375,3 @@ err:
 
        return ret;
 }
-