File nss-ECDSA-selftest-fix.patch of Package mozilla-nss.972

# HG changeset patch
# User Federico Mena Quintero <federico@suse.com>
# Parent  2e4b1156617ab1f01cbee0fa83fc13c9eab66c09
Do SECOID_Init()/Shutdown() around sftk_fips_ECDSA_Test().
Internally, SECOID_FindOID() assumes that oidhash has been
initialized, and this is done in SECOID_Init().

diff --git a/lib/softoken/fipstest.c b/lib/softoken/fipstest.c
--- a/lib/softoken/fipstest.c
+++ b/lib/softoken/fipstest.c
@@ -6,16 +6,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "softoken.h"   /* Required for RC2-ECB, RC2-CBC, RC4, DES-ECB,  */
                         /*              DES-CBC, DES3-ECB, DES3-CBC, RSA */
                         /*              and DSA.                         */
 #include "seccomon.h"   /* Required for RSA and DSA. */
 #include "lowkeyi.h"    /* Required for RSA and DSA. */
 #include "pkcs11.h"     /* Required for PKCS #11. */
+#include "secoid.h"     /* Required for ECDSA */
 #include "secerr.h"
 
 #ifndef NSS_DISABLE_ECC
 #include "ec.h"         /* Required for ECDSA */
 #endif
 
 
 /* FIPS preprocessor directives for RC2-ECB and RC2-CBC.        */
@@ -1634,38 +1635,44 @@ sftk_fips_ECDSA_Test(const PRUint8 *enco
     unsigned char sig[2*MAX_ECKEY_LEN];
     SECItem signature, digest;
     SECItem encodedparams;
     ECParams *ecparams = NULL;
     ECPrivateKey *ecdsa_private_key = NULL;
     ECPublicKey ecdsa_public_key;
     SECStatus ecdsaStatus = SECSuccess;
 
+    ecdsaStatus = SECOID_Init();
+    if (ecdsaStatus != SECSuccess) {
+	goto init_loser;
+    }
+
     /* construct the ECDSA private/public key pair */
     encodedparams.type = siBuffer;
     encodedparams.data = (unsigned char *) encodedParams;
     encodedparams.len = encodedParamsLen;
-    
-    if (EC_DecodeParams(&encodedparams, &ecparams) != SECSuccess) {
-        return( CKR_DEVICE_ERROR );
+
+    ecdsaStatus = EC_DecodeParams(&encodedparams, &ecparams);
+    if (ecdsaStatus != SECSuccess) {
+	goto loser;
     }
 
     /* Generates a new EC key pair. The private key is a supplied
      * random value (in seed) and the public key is the result of 
      * performing a scalar point multiplication of that value with 
      * the curve's base point.
      */
     ecdsaStatus = EC_NewKeyFromSeed(ecparams, &ecdsa_private_key, 
                                    ecdsa_Known_Seed, 
                                    sizeof(ecdsa_Known_Seed));
     /* free the ecparams they are no longer needed */
     PORT_FreeArena(ecparams->arena, PR_FALSE);
     ecparams = NULL;
     if (ecdsaStatus != SECSuccess) {
-        return ( CKR_DEVICE_ERROR );    
+	goto loser;
     }
 
     /* construct public key from private key. */
     ecdsaStatus = EC_CopyParams(ecdsa_private_key->ecParams.arena, 
                                 &ecdsa_public_key.ecParams,
                                 &ecdsa_private_key->ecParams);
     if (ecdsaStatus != SECSuccess) {
         goto loser;
@@ -1724,19 +1731,24 @@ sftk_fips_ECDSA_Test(const PRUint8 *enco
     ecdsaStatus = ECDSA_VerifyDigest(&ecdsa_public_key, &signature, &digest);
 
 loser:
     /* free the memory for the private key arena*/
     if (ecdsa_private_key != NULL) {
         PORT_FreeArena(ecdsa_private_key->ecParams.arena, PR_FALSE);
     }
 
+    ecdsaStatus = SECOID_Shutdown();
+
+init_loser:
+
     if (ecdsaStatus != SECSuccess) {
         return CKR_DEVICE_ERROR ;
     }
+
     return( CKR_OK );
 }
 
 static CK_RV
 sftk_fips_ECDSA_PowerUpSelfTest() {
 
    /* ECDSA Known curve nistp256 == SEC_OID_SECG_EC_SECP256R1 params */
     static const PRUint8 ecdsa_known_P256_EncodedParams[] = {