New functions CRYPTO_set_idptr_callback(),
[openssl.git] / crypto / bn / bn_blind.c
index 1f41740c956952fea973331af58f07c98d523850..ccecc63cda1780b90fe0e7b9acff9adec962cd37 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;
@@ -207,18 +209,24 @@ 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))
                {
-               BNerr(BN_F_BN_BLINDING_CONVERT,BN_R_NOT_INITIALIZED);
+               BNerr(BN_F_BN_BLINDING_CONVERT_EX,BN_R_NOT_INITIALIZED);
                return(0);
                }
 
        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)
@@ -233,7 +241,7 @@ int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *ct
        bn_check_top(n);
        if ((b->A == NULL) || (b->Ai == NULL))
                {
-               BNerr(BN_F_BN_BLINDING_INVERT,BN_R_NOT_INITIALIZED);
+               BNerr(BN_F_BN_BLINDING_INVERT_EX,BN_R_NOT_INITIALIZED);
                return(0);
                }
 
@@ -261,6 +269,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;
@@ -278,7 +296,6 @@ BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
        BN_MONT_CTX *m_ctx)
 {
        int    retry_counter = 32;
-       BIGNUM *a, *ai;
        BN_BLINDING *ret = NULL;
 
        if (b == NULL)
@@ -352,4 +369,3 @@ err:
 
        return ret;
 }
-