arrfab / rpms / shim

Forked from rpms/shim 4 years ago
Clone

Blame SOURCES/0068-Cryptlib-remove-the-unused-files.patch

4210fa
From 663a5ca59d8b0037b3d1b445ce93ae3181f03685 Mon Sep 17 00:00:00 2001
4210fa
From: Gary Ching-Pang Lin <glin@suse.com>
4210fa
Date: Tue, 30 Sep 2014 15:27:19 +0800
4210fa
Subject: [PATCH 68/74] Cryptlib: remove the unused files
4210fa
4210fa
I mistakenly added CryptPkcs7VerifyNull.c which may make Pkcs7Verify
4210fa
always return FALSE. Besides CryptPkcs7VerifyNull.c, there are some
4210fa
functions we would never use. This commit removes those files to
4210fa
avoid any potential trouble.
4210fa
4210fa
Signed-off-by: Gary Ching-Pang Lin <glin@suse.com>
4210fa
---
4210fa
 Cryptlib/Makefile                  |   5 +-
4210fa
 Cryptlib/Pk/CryptDh.c              | 328 --------------------------------
4210fa
 Cryptlib/Pk/CryptDhNull.c          | 156 +++++++++++++++
4210fa
 Cryptlib/Pk/CryptPkcs7Sign.c       | 207 --------------------
4210fa
 Cryptlib/Pk/CryptPkcs7VerifyNull.c | 100 ----------
4210fa
 Cryptlib/Pk/CryptRsaExt.c          | 377 -------------------------------------
4210fa
 Cryptlib/update.sh                 |   5 +-
4210fa
 7 files changed, 158 insertions(+), 1020 deletions(-)
4210fa
 delete mode 100644 Cryptlib/Pk/CryptDh.c
4210fa
 create mode 100644 Cryptlib/Pk/CryptDhNull.c
4210fa
 delete mode 100644 Cryptlib/Pk/CryptPkcs7Sign.c
4210fa
 delete mode 100644 Cryptlib/Pk/CryptPkcs7VerifyNull.c
4210fa
 delete mode 100644 Cryptlib/Pk/CryptRsaExt.c
4210fa
4210fa
diff --git a/Cryptlib/Makefile b/Cryptlib/Makefile
4210fa
index 73a1e2b..9719a27 100644
4210fa
--- a/Cryptlib/Makefile
4210fa
+++ b/Cryptlib/Makefile
4210fa
@@ -25,13 +25,10 @@ OBJS		=   Hash/CryptMd4.o \
4210fa
 		    Cipher/CryptArc4.o \
4210fa
 		    Rand/CryptRand.o \
4210fa
 		    Pk/CryptRsaBasic.o \
4210fa
-		    Pk/CryptRsaExt.o \
4210fa
 		    Pk/CryptRsaExtNull.o \
4210fa
-		    Pk/CryptPkcs7Sign.o \
4210fa
 		    Pk/CryptPkcs7SignNull.o \
4210fa
 		    Pk/CryptPkcs7Verify.o \
4210fa
-		    Pk/CryptPkcs7VerifyNull.o \
4210fa
-		    Pk/CryptDh.o \
4210fa
+		    Pk/CryptDhNull.o \
4210fa
 		    Pk/CryptX509.o \
4210fa
 		    Pk/CryptAuthenticode.o \
4210fa
 		    Pem/CryptPem.o \
4210fa
diff --git a/Cryptlib/Pk/CryptDh.c b/Cryptlib/Pk/CryptDh.c
4210fa
deleted file mode 100644
4210fa
index 942b3d1..0000000
4210fa
--- a/Cryptlib/Pk/CryptDh.c
4210fa
+++ /dev/null
4210fa
@@ -1,328 +0,0 @@
4210fa
-/** @file
4210fa
-  Diffie-Hellman Wrapper Implementation over OpenSSL.
4210fa
-
4210fa
-Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.
4210fa
-This program and the accompanying materials
4210fa
-are licensed and made available under the terms and conditions of the BSD License
4210fa
-which accompanies this distribution.  The full text of the license may be found at
4210fa
-http://opensource.org/licenses/bsd-license.php
4210fa
-
4210fa
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
4210fa
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
4210fa
-
4210fa
-**/
4210fa
-
4210fa
-#include "InternalCryptLib.h"
4210fa
-#include <openssl/dh.h>
4210fa
-
4210fa
-
4210fa
-/**
4210fa
-  Allocates and Initializes one Diffie-Hellman Context for subsequent use.
4210fa
-
4210fa
-  @return  Pointer to the Diffie-Hellman Context that has been initialized.
4210fa
-           If the allocations fails, DhNew() returns NULL.
4210fa
-
4210fa
-**/
4210fa
-VOID *
4210fa
-EFIAPI
4210fa
-DhNew (
4210fa
-  VOID
4210fa
-  )
4210fa
-{
4210fa
-  //
4210fa
-  // Allocates & Initializes DH Context by OpenSSL DH_new()
4210fa
-  //
4210fa
-  return (VOID *) DH_new ();
4210fa
-}
4210fa
-
4210fa
-/**
4210fa
-  Release the specified DH context.
4210fa
-
4210fa
-  If DhContext is NULL, then return FALSE.
4210fa
-
4210fa
-  @param[in]  DhContext  Pointer to the DH context to be released.
4210fa
-
4210fa
-**/
4210fa
-VOID
4210fa
-EFIAPI
4210fa
-DhFree (
4210fa
-  IN  VOID  *DhContext
4210fa
-  )
4210fa
-{
4210fa
-  //
4210fa
-  // Free OpenSSL DH Context
4210fa
-  //
4210fa
-  DH_free ((DH *) DhContext);
4210fa
-}
4210fa
-
4210fa
-/**
4210fa
-  Generates DH parameter.
4210fa
-
4210fa
-  Given generator g, and length of prime number p in bits, this function generates p,
4210fa
-  and sets DH context according to value of g and p.
4210fa
-  
4210fa
-  Before this function can be invoked, pseudorandom number generator must be correctly
4210fa
-  initialized by RandomSeed().
4210fa
-
4210fa
-  If DhContext is NULL, then return FALSE.
4210fa
-  If Prime is NULL, then return FALSE.
4210fa
-
4210fa
-  @param[in, out]  DhContext    Pointer to the DH context.
4210fa
-  @param[in]       Generator    Value of generator.
4210fa
-  @param[in]       PrimeLength  Length in bits of prime to be generated.
4210fa
-  @param[out]      Prime        Pointer to the buffer to receive the generated prime number.
4210fa
-
4210fa
-  @retval TRUE   DH pamameter generation succeeded.
4210fa
-  @retval FALSE  Value of Generator is not supported.
4210fa
-  @retval FALSE  PRNG fails to generate random prime number with PrimeLength.
4210fa
-
4210fa
-**/
4210fa
-BOOLEAN
4210fa
-EFIAPI
4210fa
-DhGenerateParameter (
4210fa
-  IN OUT  VOID   *DhContext,
4210fa
-  IN      UINTN  Generator,
4210fa
-  IN      UINTN  PrimeLength,
4210fa
-  OUT     UINT8  *Prime
4210fa
-  )
4210fa
-{
4210fa
-  BOOLEAN RetVal;
4210fa
-
4210fa
-  //
4210fa
-  // Check input parameters.
4210fa
-  //
4210fa
-  if (DhContext == NULL || Prime == NULL || PrimeLength > INT_MAX) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-
4210fa
-  if (Generator != DH_GENERATOR_2 && Generator != DH_GENERATOR_5) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-
4210fa
-  RetVal = (BOOLEAN) DH_generate_parameters_ex (DhContext, (UINT32) PrimeLength, (UINT32) Generator, NULL);
4210fa
-  if (!RetVal) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-
4210fa
-  BN_bn2bin (((DH *) DhContext)->p, Prime);
4210fa
-
4210fa
-  return TRUE;
4210fa
-}
4210fa
-
4210fa
-/**
4210fa
-  Sets generator and prime parameters for DH.
4210fa
-
4210fa
-  Given generator g, and prime number p, this function and sets DH
4210fa
-  context accordingly.
4210fa
-
4210fa
-  If DhContext is NULL, then return FALSE.
4210fa
-  If Prime is NULL, then return FALSE.
4210fa
-
4210fa
-  @param[in, out]  DhContext    Pointer to the DH context.
4210fa
-  @param[in]       Generator    Value of generator.
4210fa
-  @param[in]       PrimeLength  Length in bits of prime to be generated.
4210fa
-  @param[in]       Prime        Pointer to the prime number.
4210fa
-
4210fa
-  @retval TRUE   DH pamameter setting succeeded.
4210fa
-  @retval FALSE  Value of Generator is not supported.
4210fa
-  @retval FALSE  Value of Generator is not suitable for the Prime.
4210fa
-  @retval FALSE  Value of Prime is not a prime number.
4210fa
-  @retval FALSE  Value of Prime is not a safe prime number.
4210fa
-
4210fa
-**/
4210fa
-BOOLEAN
4210fa
-EFIAPI
4210fa
-DhSetParameter (
4210fa
-  IN OUT  VOID         *DhContext,
4210fa
-  IN      UINTN        Generator,
4210fa
-  IN      UINTN        PrimeLength,
4210fa
-  IN      CONST UINT8  *Prime
4210fa
-  )
4210fa
-{
4210fa
-  DH      *Dh;
4210fa
-  BIGNUM  *Bn;
4210fa
-
4210fa
-  //
4210fa
-  // Check input parameters.
4210fa
-  //
4210fa
-  if (DhContext == NULL || Prime == NULL || PrimeLength > INT_MAX) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-  
4210fa
-  if (Generator != DH_GENERATOR_2 && Generator != DH_GENERATOR_5) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-
4210fa
-  Bn = NULL;
4210fa
-
4210fa
-  Dh = (DH *) DhContext;
4210fa
-  Dh->g = NULL;
4210fa
-  Dh->p = BN_new ();
4210fa
-  if (Dh->p == NULL) {
4210fa
-    goto Error;
4210fa
-  }
4210fa
-  
4210fa
-  Dh->g = BN_new ();
4210fa
-  if (Dh->g == NULL) {
4210fa
-    goto Error;
4210fa
-  }
4210fa
-
4210fa
-  Bn = BN_bin2bn (Prime, (UINT32) (PrimeLength / 8), Dh->p);
4210fa
-  if (Bn == NULL) {
4210fa
-    goto Error;
4210fa
-  }
4210fa
-
4210fa
-  if (BN_set_word (Dh->g, (UINT32) Generator) == 0) {
4210fa
-    goto Error;
4210fa
-  }
4210fa
-
4210fa
-  return TRUE;
4210fa
-
4210fa
-Error:
4210fa
-
4210fa
-  if (Dh->p != NULL) {
4210fa
-    BN_free (Dh->p);
4210fa
-  }
4210fa
-
4210fa
-  if (Dh->g != NULL) {
4210fa
-    BN_free (Dh->g);
4210fa
-  }
4210fa
-
4210fa
-  if (Bn != NULL) {
4210fa
-    BN_free (Bn);
4210fa
-  }
4210fa
-  
4210fa
-  return FALSE;
4210fa
-}
4210fa
-
4210fa
-/**
4210fa
-  Generates DH public key.
4210fa
-
4210fa
-  This function generates random secret exponent, and computes the public key, which is 
4210fa
-  returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
4210fa
-  If the PublicKey buffer is too small to hold the public key, FALSE is returned and
4210fa
-  PublicKeySize is set to the required buffer size to obtain the public key.
4210fa
-
4210fa
-  If DhContext is NULL, then return FALSE.
4210fa
-  If PublicKeySize is NULL, then return FALSE.
4210fa
-  If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
4210fa
-
4210fa
-  @param[in, out]  DhContext      Pointer to the DH context.
4210fa
-  @param[out]      PublicKey      Pointer to the buffer to receive generated public key.
4210fa
-  @param[in, out]  PublicKeySize  On input, the size of PublicKey buffer in bytes.
4210fa
-                                  On output, the size of data returned in PublicKey buffer in bytes.
4210fa
-
4210fa
-  @retval TRUE   DH public key generation succeeded.
4210fa
-  @retval FALSE  DH public key generation failed.
4210fa
-  @retval FALSE  PublicKeySize is not large enough.
4210fa
-
4210fa
-**/
4210fa
-BOOLEAN
4210fa
-EFIAPI
4210fa
-DhGenerateKey (
4210fa
-  IN OUT  VOID   *DhContext,
4210fa
-  OUT     UINT8  *PublicKey,
4210fa
-  IN OUT  UINTN  *PublicKeySize
4210fa
-  )
4210fa
-{
4210fa
-  BOOLEAN RetVal;
4210fa
-  DH      *Dh;
4210fa
-  INTN    Size;
4210fa
-
4210fa
-  //
4210fa
-  // Check input parameters.
4210fa
-  //
4210fa
-  if (DhContext == NULL || PublicKeySize == NULL) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-
4210fa
-  if (PublicKey == NULL && *PublicKeySize != 0) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-  
4210fa
-  Dh = (DH *) DhContext;
4210fa
-
4210fa
-  RetVal = (BOOLEAN) DH_generate_key (DhContext);
4210fa
-  if (RetVal) {
4210fa
-    Size = BN_num_bytes (Dh->pub_key);
4210fa
-    if ((Size > 0) && (*PublicKeySize < (UINTN) Size)) {
4210fa
-      *PublicKeySize = Size;
4210fa
-      return FALSE;
4210fa
-    }
4210fa
-    
4210fa
-    BN_bn2bin (Dh->pub_key, PublicKey);
4210fa
-    *PublicKeySize = Size;
4210fa
-  }
4210fa
-
4210fa
-  return RetVal;
4210fa
-}
4210fa
-
4210fa
-/**
4210fa
-  Computes exchanged common key.
4210fa
-
4210fa
-  Given peer's public key, this function computes the exchanged common key, based on its own
4210fa
-  context including value of prime modulus and random secret exponent. 
4210fa
-
4210fa
-  If DhContext is NULL, then return FALSE.
4210fa
-  If PeerPublicKey is NULL, then return FALSE.
4210fa
-  If KeySize is NULL, then return FALSE.
4210fa
-  If Key is NULL, then return FALSE.
4210fa
-  If KeySize is not large enough, then return FALSE.
4210fa
-
4210fa
-  @param[in, out]  DhContext          Pointer to the DH context.
4210fa
-  @param[in]       PeerPublicKey      Pointer to the peer's public key.
4210fa
-  @param[in]       PeerPublicKeySize  Size of peer's public key in bytes.
4210fa
-  @param[out]      Key                Pointer to the buffer to receive generated key.
4210fa
-  @param[in, out]  KeySize            On input, the size of Key buffer in bytes.
4210fa
-                                      On output, the size of data returned in Key buffer in bytes.
4210fa
-
4210fa
-  @retval TRUE   DH exchanged key generation succeeded.
4210fa
-  @retval FALSE  DH exchanged key generation failed.
4210fa
-  @retval FALSE  KeySize is not large enough.
4210fa
-
4210fa
-**/
4210fa
-BOOLEAN
4210fa
-EFIAPI
4210fa
-DhComputeKey (
4210fa
-  IN OUT  VOID         *DhContext,
4210fa
-  IN      CONST UINT8  *PeerPublicKey,
4210fa
-  IN      UINTN        PeerPublicKeySize,
4210fa
-  OUT     UINT8        *Key,
4210fa
-  IN OUT  UINTN        *KeySize
4210fa
-  )
4210fa
-{
4210fa
-  BIGNUM  *Bn;
4210fa
-  INTN    Size;
4210fa
-
4210fa
-  //
4210fa
-  // Check input parameters.
4210fa
-  //
4210fa
-  if (DhContext == NULL || PeerPublicKey == NULL || KeySize == NULL || Key == NULL) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-
4210fa
-  if (PeerPublicKeySize > INT_MAX) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-  
4210fa
-  Bn = BN_bin2bn (PeerPublicKey, (UINT32) PeerPublicKeySize, NULL);
4210fa
-  if (Bn == NULL) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-
4210fa
-  Size = DH_compute_key (Key, Bn, DhContext);
4210fa
-  if (Size < 0) {
4210fa
-    BN_free (Bn);
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-
4210fa
-  if (*KeySize < (UINTN) Size) {
4210fa
-    *KeySize = Size;
4210fa
-    BN_free (Bn);
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-
4210fa
-  *KeySize = Size;
4210fa
-  BN_free (Bn);
4210fa
-  return TRUE;
4210fa
-}
4210fa
diff --git a/Cryptlib/Pk/CryptDhNull.c b/Cryptlib/Pk/CryptDhNull.c
4210fa
new file mode 100644
4210fa
index 0000000..35045db
4210fa
--- /dev/null
4210fa
+++ b/Cryptlib/Pk/CryptDhNull.c
4210fa
@@ -0,0 +1,156 @@
4210fa
+/** @file
4210fa
+  Diffie-Hellman Wrapper Implementation which does not provide
4210fa
+  real capabilities.
4210fa
+
4210fa
+Copyright (c) 2012, Intel Corporation. All rights reserved.
4210fa
+This program and the accompanying materials
4210fa
+are licensed and made available under the terms and conditions of the BSD License
4210fa
+which accompanies this distribution.  The full text of the license may be found at
4210fa
+http://opensource.org/licenses/bsd-license.php
4210fa
+
4210fa
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
4210fa
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
4210fa
+
4210fa
+**/
4210fa
+
4210fa
+#include "InternalCryptLib.h"
4210fa
+
4210fa
+/**
4210fa
+  Allocates and Initializes one Diffie-Hellman Context for subsequent use.
4210fa
+
4210fa
+  @return  Pointer to the Diffie-Hellman Context that has been initialized.
4210fa
+           If the interface is not supported, DhNew() returns NULL.
4210fa
+
4210fa
+**/
4210fa
+VOID *
4210fa
+EFIAPI
4210fa
+DhNew (
4210fa
+  VOID
4210fa
+  )
4210fa
+{
4210fa
+  ASSERT (FALSE);
4210fa
+  return NULL;
4210fa
+}
4210fa
+
4210fa
+/**
4210fa
+  Release the specified DH context.
4210fa
+
4210fa
+  If the interface is not supported, then ASSERT().
4210fa
+
4210fa
+  @param[in]  DhContext  Pointer to the DH context to be released.
4210fa
+
4210fa
+**/
4210fa
+VOID
4210fa
+EFIAPI
4210fa
+DhFree (
4210fa
+  IN  VOID  *DhContext
4210fa
+  )
4210fa
+{
4210fa
+  ASSERT (FALSE);
4210fa
+}
4210fa
+
4210fa
+/**
4210fa
+  Generates DH parameter.
4210fa
+
4210fa
+  Return FALSE to indicate this interface is not supported.
4210fa
+
4210fa
+  @param[in, out]  DhContext    Pointer to the DH context.
4210fa
+  @param[in]       Generator    Value of generator.
4210fa
+  @param[in]       PrimeLength  Length in bits of prime to be generated.
4210fa
+  @param[out]      Prime        Pointer to the buffer to receive the generated prime number.
4210fa
+
4210fa
+  @retval FALSE  This interface is not supported.
4210fa
+
4210fa
+**/
4210fa
+BOOLEAN
4210fa
+EFIAPI
4210fa
+DhGenerateParameter (
4210fa
+  IN OUT  VOID   *DhContext,
4210fa
+  IN      UINTN  Generator,
4210fa
+  IN      UINTN  PrimeLength,
4210fa
+  OUT     UINT8  *Prime
4210fa
+  )
4210fa
+{
4210fa
+  ASSERT (FALSE);
4210fa
+  return FALSE;
4210fa
+}
4210fa
+
4210fa
+/**
4210fa
+  Sets generator and prime parameters for DH.
4210fa
+
4210fa
+  Return FALSE to indicate this interface is not supported.
4210fa
+
4210fa
+  @param[in, out]  DhContext    Pointer to the DH context.
4210fa
+  @param[in]       Generator    Value of generator.
4210fa
+  @param[in]       PrimeLength  Length in bits of prime to be generated.
4210fa
+  @param[in]       Prime        Pointer to the prime number.
4210fa
+
4210fa
+  @retval FALSE  This interface is not supported.
4210fa
+
4210fa
+**/
4210fa
+BOOLEAN
4210fa
+EFIAPI
4210fa
+DhSetParameter (
4210fa
+  IN OUT  VOID         *DhContext,
4210fa
+  IN      UINTN        Generator,
4210fa
+  IN      UINTN        PrimeLength,
4210fa
+  IN      CONST UINT8  *Prime
4210fa
+  )
4210fa
+{
4210fa
+  ASSERT (FALSE);
4210fa
+  return FALSE; 
4210fa
+}
4210fa
+
4210fa
+/**
4210fa
+  Generates DH public key.
4210fa
+
4210fa
+  Return FALSE to indicate this interface is not supported.
4210fa
+
4210fa
+  @param[in, out]  DhContext      Pointer to the DH context.
4210fa
+  @param[out]      PublicKey      Pointer to the buffer to receive generated public key.
4210fa
+  @param[in, out]  PublicKeySize  On input, the size of PublicKey buffer in bytes.
4210fa
+                                  On output, the size of data returned in PublicKey buffer in bytes.
4210fa
+
4210fa
+  @retval FALSE  This interface is not supported.
4210fa
+
4210fa
+**/
4210fa
+BOOLEAN
4210fa
+EFIAPI
4210fa
+DhGenerateKey (
4210fa
+  IN OUT  VOID   *DhContext,
4210fa
+  OUT     UINT8  *PublicKey,
4210fa
+  IN OUT  UINTN  *PublicKeySize
4210fa
+  )
4210fa
+{
4210fa
+  ASSERT (FALSE);
4210fa
+  return FALSE;
4210fa
+}
4210fa
+
4210fa
+/**
4210fa
+  Computes exchanged common key.
4210fa
+
4210fa
+  Return FALSE to indicate this interface is not supported.
4210fa
+
4210fa
+  @param[in, out]  DhContext          Pointer to the DH context.
4210fa
+  @param[in]       PeerPublicKey      Pointer to the peer's public key.
4210fa
+  @param[in]       PeerPublicKeySize  Size of peer's public key in bytes.
4210fa
+  @param[out]      Key                Pointer to the buffer to receive generated key.
4210fa
+  @param[in, out]  KeySize            On input, the size of Key buffer in bytes.
4210fa
+                                      On output, the size of data returned in Key buffer in bytes.
4210fa
+
4210fa
+  @retval FALSE  This interface is not supported.
4210fa
+
4210fa
+**/
4210fa
+BOOLEAN
4210fa
+EFIAPI
4210fa
+DhComputeKey (
4210fa
+  IN OUT  VOID         *DhContext,
4210fa
+  IN      CONST UINT8  *PeerPublicKey,
4210fa
+  IN      UINTN        PeerPublicKeySize,
4210fa
+  OUT     UINT8        *Key,
4210fa
+  IN OUT  UINTN        *KeySize
4210fa
+  )
4210fa
+{
4210fa
+  ASSERT (FALSE);
4210fa
+  return FALSE;
4210fa
+}
4210fa
diff --git a/Cryptlib/Pk/CryptPkcs7Sign.c b/Cryptlib/Pk/CryptPkcs7Sign.c
4210fa
deleted file mode 100644
4210fa
index 63fe78f..0000000
4210fa
--- a/Cryptlib/Pk/CryptPkcs7Sign.c
4210fa
+++ /dev/null
4210fa
@@ -1,207 +0,0 @@
4210fa
-/** @file
4210fa
-  PKCS#7 SignedData Sign Wrapper Implementation over OpenSSL.
4210fa
-
4210fa
-Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.
4210fa
-This program and the accompanying materials
4210fa
-are licensed and made available under the terms and conditions of the BSD License
4210fa
-which accompanies this distribution.  The full text of the license may be found at
4210fa
-http://opensource.org/licenses/bsd-license.php
4210fa
-
4210fa
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
4210fa
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
4210fa
-
4210fa
-**/
4210fa
-
4210fa
-#include "InternalCryptLib.h"
4210fa
-
4210fa
-#include <openssl/objects.h>
4210fa
-#include <openssl/x509.h>
4210fa
-#include <openssl/pkcs7.h>
4210fa
-
4210fa
-
4210fa
-/**
4210fa
-  Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
4210fa
-  Syntax Standard, version 1.5". This interface is only intended to be used for
4210fa
-  application to perform PKCS#7 functionality validation.
4210fa
-
4210fa
-  @param[in]  PrivateKey       Pointer to the PEM-formatted private key data for
4210fa
-                               data signing.
4210fa
-  @param[in]  PrivateKeySize   Size of the PEM private key data in bytes.
4210fa
-  @param[in]  KeyPassword      NULL-terminated passphrase used for encrypted PEM
4210fa
-                               key data.
4210fa
-  @param[in]  InData           Pointer to the content to be signed.
4210fa
-  @param[in]  InDataSize       Size of InData in bytes.
4210fa
-  @param[in]  SignCert         Pointer to signer's DER-encoded certificate to sign with.
4210fa
-  @param[in]  OtherCerts       Pointer to an optional additional set of certificates to
4210fa
-                               include in the PKCS#7 signedData (e.g. any intermediate
4210fa
-                               CAs in the chain).
4210fa
-  @param[out] SignedData       Pointer to output PKCS#7 signedData.
4210fa
-  @param[out] SignedDataSize   Size of SignedData in bytes.
4210fa
-
4210fa
-  @retval     TRUE             PKCS#7 data signing succeeded.
4210fa
-  @retval     FALSE            PKCS#7 data signing failed.
4210fa
-
4210fa
-**/
4210fa
-BOOLEAN
4210fa
-EFIAPI
4210fa
-Pkcs7Sign (
4210fa
-  IN   CONST UINT8  *PrivateKey,
4210fa
-  IN   UINTN        PrivateKeySize,
4210fa
-  IN   CONST UINT8  *KeyPassword,
4210fa
-  IN   UINT8        *InData,
4210fa
-  IN   UINTN        InDataSize,
4210fa
-  IN   UINT8        *SignCert,
4210fa
-  IN   UINT8        *OtherCerts      OPTIONAL,
4210fa
-  OUT  UINT8        **SignedData,
4210fa
-  OUT  UINTN        *SignedDataSize
4210fa
-  )
4210fa
-{
4210fa
-  BOOLEAN   Status;
4210fa
-  EVP_PKEY  *Key;
4210fa
-  BIO       *DataBio;
4210fa
-  PKCS7     *Pkcs7;
4210fa
-  UINT8     *RsaContext;
4210fa
-  UINT8     *P7Data;
4210fa
-  UINTN     P7DataSize;
4210fa
-  UINT8     *Tmp;
4210fa
-
4210fa
-  //
4210fa
-  // Check input parameters.
4210fa
-  //
4210fa
-  if (PrivateKey == NULL || KeyPassword == NULL || InData == NULL ||
4210fa
-    SignCert == NULL || SignedData == NULL || SignedDataSize == NULL || InDataSize > INT_MAX) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-
4210fa
-  RsaContext = NULL;
4210fa
-  Key        = NULL;
4210fa
-  Pkcs7      = NULL;
4210fa
-  DataBio    = NULL;
4210fa
-  Status     = FALSE;
4210fa
-
4210fa
-  //
4210fa
-  // Retrieve RSA private key from PEM data.
4210fa
-  //
4210fa
-  Status = RsaGetPrivateKeyFromPem (
4210fa
-             PrivateKey,
4210fa
-             PrivateKeySize,
4210fa
-             (CONST CHAR8 *) KeyPassword,
4210fa
-             (VOID **) &RsaContext
4210fa
-             );
4210fa
-  if (!Status) {
4210fa
-    return Status;
4210fa
-  }
4210fa
-
4210fa
-  Status = FALSE;
4210fa
-
4210fa
-  //
4210fa
-  // Register & Initialize necessary digest algorithms and PRNG for PKCS#7 Handling
4210fa
-  //
4210fa
-  if (EVP_add_digest (EVP_md5 ()) == 0) {
4210fa
-    goto _Exit;
4210fa
-  }
4210fa
-  if (EVP_add_digest (EVP_sha1 ()) == 0) {
4210fa
-    goto _Exit;
4210fa
-  }
4210fa
-  if (EVP_add_digest (EVP_sha256 ()) == 0) {
4210fa
-    goto _Exit;
4210fa
-  }
4210fa
-
4210fa
-  RandomSeed (NULL, 0);
4210fa
-
4210fa
-  //
4210fa
-  // Construct OpenSSL EVP_PKEY for private key.
4210fa
-  //
4210fa
-  Key = EVP_PKEY_new ();
4210fa
-  if (Key == NULL) {
4210fa
-    goto _Exit;
4210fa
-  }
4210fa
-  Key->save_type = EVP_PKEY_RSA;
4210fa
-  Key->type      = EVP_PKEY_type (EVP_PKEY_RSA);
4210fa
-  Key->pkey.rsa  = (RSA *) RsaContext;
4210fa
-
4210fa
-  //
4210fa
-  // Convert the data to be signed to BIO format. 
4210fa
-  //
4210fa
-  DataBio = BIO_new (BIO_s_mem ());
4210fa
-  if (DataBio == NULL) {
4210fa
-    goto _Exit;
4210fa
-  }
4210fa
-
4210fa
-  if (BIO_write (DataBio, InData, (int) InDataSize) <= 0) {
4210fa
-    goto _Exit;
4210fa
-  }
4210fa
-
4210fa
-  //
4210fa
-  // Create the PKCS#7 signedData structure.
4210fa
-  //
4210fa
-  Pkcs7 = PKCS7_sign (
4210fa
-            (X509 *) SignCert,
4210fa
-            Key,
4210fa
-            (STACK_OF(X509) *) OtherCerts,
4210fa
-            DataBio,
4210fa
-            PKCS7_BINARY | PKCS7_NOATTR | PKCS7_DETACHED
4210fa
-            );
4210fa
-  if (Pkcs7 == NULL) {
4210fa
-    goto _Exit;
4210fa
-  }
4210fa
-
4210fa
-  //
4210fa
-  // Convert PKCS#7 signedData structure into DER-encoded buffer.
4210fa
-  //
4210fa
-  P7DataSize = i2d_PKCS7 (Pkcs7, NULL);
4210fa
-  if (P7DataSize <= 19) {
4210fa
-    goto _Exit;
4210fa
-  }
4210fa
-
4210fa
-  P7Data     = malloc (P7DataSize);
4210fa
-  if (P7Data == NULL) {
4210fa
-    goto _Exit;
4210fa
-  }
4210fa
-
4210fa
-  Tmp        = P7Data;
4210fa
-  P7DataSize = i2d_PKCS7 (Pkcs7, (unsigned char **) &Tmp);
4210fa
-  ASSERT (P7DataSize > 19);
4210fa
-
4210fa
-  //
4210fa
-  // Strip ContentInfo to content only for signeddata. The data be trimmed off
4210fa
-  // is totally 19 bytes.
4210fa
-  //
4210fa
-  *SignedDataSize = P7DataSize - 19;
4210fa
-  *SignedData     = malloc (*SignedDataSize);
4210fa
-  if (*SignedData == NULL) {
4210fa
-    OPENSSL_free (P7Data);
4210fa
-    goto _Exit;
4210fa
-  }
4210fa
-
4210fa
-  CopyMem (*SignedData, P7Data + 19, *SignedDataSize);
4210fa
-  
4210fa
-  OPENSSL_free (P7Data);
4210fa
-
4210fa
-  Status = TRUE;
4210fa
-
4210fa
-_Exit:
4210fa
-  //
4210fa
-  // Release Resources
4210fa
-  //
4210fa
-  if (RsaContext != NULL) {
4210fa
-    RsaFree (RsaContext);
4210fa
-    if (Key != NULL) {
4210fa
-      Key->pkey.rsa = NULL;
4210fa
-    }
4210fa
-  }
4210fa
-
4210fa
-  if (Key != NULL) {
4210fa
-    EVP_PKEY_free (Key);
4210fa
-  }
4210fa
-
4210fa
-  if (DataBio != NULL) {
4210fa
-    BIO_free (DataBio);
4210fa
-  }
4210fa
-
4210fa
-  if (Pkcs7 != NULL) {
4210fa
-    PKCS7_free (Pkcs7);
4210fa
-  }
4210fa
-
4210fa
-  return Status;
4210fa
-}
4210fa
diff --git a/Cryptlib/Pk/CryptPkcs7VerifyNull.c b/Cryptlib/Pk/CryptPkcs7VerifyNull.c
4210fa
deleted file mode 100644
4210fa
index 9a4c77a..0000000
4210fa
--- a/Cryptlib/Pk/CryptPkcs7VerifyNull.c
4210fa
+++ /dev/null
4210fa
@@ -1,100 +0,0 @@
4210fa
-/** @file
4210fa
-  PKCS#7 SignedData Verification Wrapper Implementation which does not provide
4210fa
-  real capabilities.
4210fa
-
4210fa
-Copyright (c) 2012, Intel Corporation. All rights reserved.
4210fa
-This program and the accompanying materials
4210fa
-are licensed and made available under the terms and conditions of the BSD License
4210fa
-which accompanies this distribution.  The full text of the license may be found at
4210fa
-http://opensource.org/licenses/bsd-license.php
4210fa
-
4210fa
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
4210fa
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
4210fa
-
4210fa
-**/
4210fa
-
4210fa
-#include "InternalCryptLib.h"
4210fa
-
4210fa
-/**
4210fa
-  Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
4210fa
-  Cryptographic Message Syntax Standard". The input signed data could be wrapped
4210fa
-  in a ContentInfo structure.
4210fa
-
4210fa
-  Return FALSE to indicate this interface is not supported.
4210fa
-
4210fa
-  @param[in]  P7Data       Pointer to the PKCS#7 message to verify.
4210fa
-  @param[in]  P7Length     Length of the PKCS#7 message in bytes.
4210fa
-  @param[out] CertStack    Pointer to Signer's certificates retrieved from P7Data.
4210fa
-                           It's caller's responsiblity to free the buffer.
4210fa
-  @param[out] StackLength  Length of signer's certificates in bytes.
4210fa
-  @param[out] TrustedCert  Pointer to a trusted certificate from Signer's certificates.
4210fa
-                           It's caller's responsiblity to free the buffer.
4210fa
-  @param[out] CertLength   Length of the trusted certificate in bytes.
4210fa
-
4210fa
-  @retval FALSE  This interface is not supported.
4210fa
-
4210fa
-**/
4210fa
-BOOLEAN
4210fa
-EFIAPI
4210fa
-Pkcs7GetSigners (
4210fa
-  IN  CONST UINT8  *P7Data,
4210fa
-  IN  UINTN        P7Length,
4210fa
-  OUT UINT8        **CertStack,
4210fa
-  OUT UINTN        *StackLength,
4210fa
-  OUT UINT8        **TrustedCert,
4210fa
-  OUT UINTN        *CertLength
4210fa
-  )
4210fa
-{
4210fa
-  ASSERT (FALSE);
4210fa
-  return FALSE;
4210fa
-}
4210fa
-
4210fa
-/**
4210fa
-  Wrap function to use free() to free allocated memory for certificates.
4210fa
-
4210fa
-  If the interface is not supported, then ASSERT().
4210fa
-  
4210fa
-  @param[in]  Certs        Pointer to the certificates to be freed.
4210fa
-
4210fa
-**/
4210fa
-VOID
4210fa
-EFIAPI
4210fa
-Pkcs7FreeSigners (
4210fa
-  IN  UINT8        *Certs
4210fa
-  )
4210fa
-{
4210fa
-  ASSERT (FALSE);
4210fa
-}
4210fa
-
4210fa
-/**
4210fa
-  Verifies the validility of a PKCS#7 signed data as described in "PKCS #7:
4210fa
-  Cryptographic Message Syntax Standard". The input signed data could be wrapped
4210fa
-  in a ContentInfo structure.
4210fa
-
4210fa
-  Return FALSE to indicate this interface is not supported.
4210fa
-
4210fa
-  @param[in]  P7Data       Pointer to the PKCS#7 message to verify.
4210fa
-  @param[in]  P7Length     Length of the PKCS#7 message in bytes.
4210fa
-  @param[in]  TrustedCert  Pointer to a trusted/root certificate encoded in DER, which
4210fa
-                           is used for certificate chain verification.
4210fa
-  @param[in]  CertLength   Length of the trusted certificate in bytes.
4210fa
-  @param[in]  InData       Pointer to the content to be verified.
4210fa
-  @param[in]  DataLength   Length of InData in bytes.
4210fa
-
4210fa
-  @retval FALSE  This interface is not supported.
4210fa
-
4210fa
-**/
4210fa
-BOOLEAN
4210fa
-EFIAPI
4210fa
-Pkcs7Verify (
4210fa
-  IN  CONST UINT8  *P7Data,
4210fa
-  IN  UINTN        P7Length,
4210fa
-  IN  CONST UINT8  *TrustedCert,
4210fa
-  IN  UINTN        CertLength,
4210fa
-  IN  CONST UINT8  *InData,
4210fa
-  IN  UINTN        DataLength
4210fa
-  )
4210fa
-{
4210fa
-  ASSERT (FALSE);
4210fa
-  return FALSE;
4210fa
-}
4210fa
diff --git a/Cryptlib/Pk/CryptRsaExt.c b/Cryptlib/Pk/CryptRsaExt.c
4210fa
deleted file mode 100644
4210fa
index 5c21d12..0000000
4210fa
--- a/Cryptlib/Pk/CryptRsaExt.c
4210fa
+++ /dev/null
4210fa
@@ -1,377 +0,0 @@
4210fa
-/** @file
4210fa
-  RSA Asymmetric Cipher Wrapper Implementation over OpenSSL.
4210fa
-
4210fa
-  This file implements following APIs which provide more capabilities for RSA:
4210fa
-  1) RsaGetKey
4210fa
-  2) RsaGenerateKey
4210fa
-  3) RsaCheckKey
4210fa
-  4) RsaPkcs1Sign
4210fa
-
4210fa
-Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.
4210fa
-This program and the accompanying materials
4210fa
-are licensed and made available under the terms and conditions of the BSD License
4210fa
-which accompanies this distribution.  The full text of the license may be found at
4210fa
-http://opensource.org/licenses/bsd-license.php
4210fa
-
4210fa
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
4210fa
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
4210fa
-
4210fa
-**/
4210fa
-
4210fa
-#include "InternalCryptLib.h"
4210fa
-
4210fa
-#include <openssl/rsa.h>
4210fa
-#include <openssl/err.h>
4210fa
-#include <openssl/objects.h>
4210fa
-
4210fa
-/**
4210fa
-  Gets the tag-designated RSA key component from the established RSA context.
4210fa
-
4210fa
-  This function retrieves the tag-designated RSA key component from the
4210fa
-  established RSA context as a non-negative integer (octet string format
4210fa
-  represented in RSA PKCS#1).
4210fa
-  If specified key component has not been set or has been cleared, then returned
4210fa
-  BnSize is set to 0.
4210fa
-  If the BigNumber buffer is too small to hold the contents of the key, FALSE
4210fa
-  is returned and BnSize is set to the required buffer size to obtain the key.
4210fa
-
4210fa
-  If RsaContext is NULL, then return FALSE.
4210fa
-  If BnSize is NULL, then return FALSE.
4210fa
-  If BnSize is large enough but BigNumber is NULL, then return FALSE.
4210fa
-
4210fa
-  @param[in, out]  RsaContext  Pointer to RSA context being set.
4210fa
-  @param[in]       KeyTag      Tag of RSA key component being set.
4210fa
-  @param[out]      BigNumber   Pointer to octet integer buffer.
4210fa
-  @param[in, out]  BnSize      On input, the size of big number buffer in bytes.
4210fa
-                               On output, the size of data returned in big number buffer in bytes.
4210fa
-
4210fa
-  @retval  TRUE   RSA key component was retrieved successfully.
4210fa
-  @retval  FALSE  Invalid RSA key component tag.
4210fa
-  @retval  FALSE  BnSize is too small.
4210fa
-
4210fa
-**/
4210fa
-BOOLEAN
4210fa
-EFIAPI
4210fa
-RsaGetKey (
4210fa
-  IN OUT  VOID         *RsaContext,
4210fa
-  IN      RSA_KEY_TAG  KeyTag,
4210fa
-  OUT     UINT8        *BigNumber,
4210fa
-  IN OUT  UINTN        *BnSize
4210fa
-  )
4210fa
-{
4210fa
-  RSA    *RsaKey;
4210fa
-  BIGNUM *BnKey;
4210fa
-  UINTN  Size;
4210fa
-
4210fa
-  //
4210fa
-  // Check input parameters.
4210fa
-  //
4210fa
-  if (RsaContext == NULL || BnSize == NULL) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-
4210fa
-  RsaKey  = (RSA *) RsaContext;
4210fa
-  Size    = *BnSize;
4210fa
-  *BnSize = 0;
4210fa
-
4210fa
-  switch (KeyTag) {
4210fa
-
4210fa
-  //
4210fa
-  // RSA Public Modulus (N)
4210fa
-  //
4210fa
-  case RsaKeyN:
4210fa
-    if (RsaKey->n == NULL) {
4210fa
-      return TRUE;
4210fa
-    }
4210fa
-    BnKey = RsaKey->n;
4210fa
-    break;
4210fa
-
4210fa
-  //
4210fa
-  // RSA Public Exponent (e)
4210fa
-  //
4210fa
-  case RsaKeyE:
4210fa
-    if (RsaKey->e == NULL) {
4210fa
-      return TRUE;
4210fa
-    }
4210fa
-    BnKey = RsaKey->e;
4210fa
-    break;
4210fa
-
4210fa
-  //
4210fa
-  // RSA Private Exponent (d)
4210fa
-  //
4210fa
-  case RsaKeyD:
4210fa
-    if (RsaKey->d == NULL) {
4210fa
-      return TRUE;
4210fa
-    }
4210fa
-    BnKey = RsaKey->d;
4210fa
-    break;
4210fa
-
4210fa
-  //
4210fa
-  // RSA Secret Prime Factor of Modulus (p)
4210fa
-  //
4210fa
-  case RsaKeyP:
4210fa
-    if (RsaKey->p == NULL) {
4210fa
-      return TRUE;
4210fa
-    }
4210fa
-    BnKey = RsaKey->p;
4210fa
-    break;
4210fa
-
4210fa
-  //
4210fa
-  // RSA Secret Prime Factor of Modules (q)
4210fa
-  //
4210fa
-  case RsaKeyQ:
4210fa
-    if (RsaKey->q == NULL) {
4210fa
-      return TRUE;
4210fa
-    }
4210fa
-    BnKey = RsaKey->q;
4210fa
-    break;
4210fa
-
4210fa
-  //
4210fa
-  // p's CRT Exponent (== d mod (p - 1))
4210fa
-  //
4210fa
-  case RsaKeyDp:
4210fa
-    if (RsaKey->dmp1 == NULL) {
4210fa
-      return TRUE;
4210fa
-    }
4210fa
-    BnKey = RsaKey->dmp1;
4210fa
-    break;
4210fa
-
4210fa
-  //
4210fa
-  // q's CRT Exponent (== d mod (q - 1))
4210fa
-  //
4210fa
-  case RsaKeyDq:
4210fa
-    if (RsaKey->dmq1 == NULL) {
4210fa
-      return TRUE;
4210fa
-    }
4210fa
-    BnKey = RsaKey->dmq1;
4210fa
-    break;
4210fa
-
4210fa
-  //
4210fa
-  // The CRT Coefficient (== 1/q mod p)
4210fa
-  //
4210fa
-  case RsaKeyQInv:
4210fa
-    if (RsaKey->iqmp == NULL) {
4210fa
-      return TRUE;
4210fa
-    }
4210fa
-    BnKey = RsaKey->iqmp;
4210fa
-    break;
4210fa
-
4210fa
-  default:
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-
4210fa
-  *BnSize = Size;
4210fa
-  Size    = BN_num_bytes (BnKey);
4210fa
-
4210fa
-  if (*BnSize < Size) {
4210fa
-    *BnSize = Size;
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-
4210fa
-  if (BigNumber == NULL) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-  *BnSize = BN_bn2bin (BnKey, BigNumber) ;
4210fa
-  
4210fa
-  return TRUE;
4210fa
-}
4210fa
-
4210fa
-/**
4210fa
-  Generates RSA key components.
4210fa
-
4210fa
-  This function generates RSA key components. It takes RSA public exponent E and
4210fa
-  length in bits of RSA modulus N as input, and generates all key components.
4210fa
-  If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
4210fa
-
4210fa
-  Before this function can be invoked, pseudorandom number generator must be correctly
4210fa
-  initialized by RandomSeed().
4210fa
-
4210fa
-  If RsaContext is NULL, then return FALSE.
4210fa
-
4210fa
-  @param[in, out]  RsaContext           Pointer to RSA context being set.
4210fa
-  @param[in]       ModulusLength        Length of RSA modulus N in bits.
4210fa
-  @param[in]       PublicExponent       Pointer to RSA public exponent.
4210fa
-  @param[in]       PublicExponentSize   Size of RSA public exponent buffer in bytes. 
4210fa
-
4210fa
-  @retval  TRUE   RSA key component was generated successfully.
4210fa
-  @retval  FALSE  Invalid RSA key component tag.
4210fa
-
4210fa
-**/
4210fa
-BOOLEAN
4210fa
-EFIAPI
4210fa
-RsaGenerateKey (
4210fa
-  IN OUT  VOID         *RsaContext,
4210fa
-  IN      UINTN        ModulusLength,
4210fa
-  IN      CONST UINT8  *PublicExponent,
4210fa
-  IN      UINTN        PublicExponentSize
4210fa
-  )
4210fa
-{
4210fa
-  BIGNUM   *KeyE;
4210fa
-  BOOLEAN  RetVal;
4210fa
-
4210fa
-  //
4210fa
-  // Check input parameters.
4210fa
-  //
4210fa
-  if (RsaContext == NULL || ModulusLength > INT_MAX || PublicExponentSize > INT_MAX) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-  
4210fa
-  KeyE = BN_new ();
4210fa
-  if (KeyE == NULL) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-
4210fa
-  RetVal = FALSE;
4210fa
-  
4210fa
-  if (PublicExponent == NULL) {
4210fa
-    if (BN_set_word (KeyE, 0x10001) == 0) {
4210fa
-      goto _Exit;
4210fa
-    }
4210fa
-  } else {
4210fa
-    if (BN_bin2bn (PublicExponent, (UINT32) PublicExponentSize, KeyE) == NULL) {
4210fa
-      goto _Exit;
4210fa
-    }
4210fa
-  }
4210fa
-
4210fa
-  if (RSA_generate_key_ex ((RSA *) RsaContext, (UINT32) ModulusLength, KeyE, NULL) == 1) {
4210fa
-   RetVal = TRUE;
4210fa
-  }
4210fa
-
4210fa
-_Exit:
4210fa
-  BN_free (KeyE);
4210fa
-  return RetVal;
4210fa
-}
4210fa
-
4210fa
-/**
4210fa
-  Validates key components of RSA context.
4210fa
-
4210fa
-  This function validates key compoents of RSA context in following aspects:
4210fa
-  - Whether p is a prime
4210fa
-  - Whether q is a prime
4210fa
-  - Whether n = p * q
4210fa
-  - Whether d*e = 1  mod lcm(p-1,q-1)
4210fa
-
4210fa
-  If RsaContext is NULL, then return FALSE.
4210fa
-
4210fa
-  @param[in]  RsaContext  Pointer to RSA context to check.
4210fa
-
4210fa
-  @retval  TRUE   RSA key components are valid.
4210fa
-  @retval  FALSE  RSA key components are not valid.
4210fa
-
4210fa
-**/
4210fa
-BOOLEAN
4210fa
-EFIAPI
4210fa
-RsaCheckKey (
4210fa
-  IN  VOID  *RsaContext
4210fa
-  )
4210fa
-{
4210fa
-  UINTN  Reason;
4210fa
-
4210fa
-  //
4210fa
-  // Check input parameters.
4210fa
-  //
4210fa
-  if (RsaContext == NULL) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-  
4210fa
-  if  (RSA_check_key ((RSA *) RsaContext) != 1) {
4210fa
-    Reason = ERR_GET_REASON (ERR_peek_last_error ());
4210fa
-    if (Reason == RSA_R_P_NOT_PRIME ||
4210fa
-        Reason == RSA_R_Q_NOT_PRIME ||
4210fa
-        Reason == RSA_R_N_DOES_NOT_EQUAL_P_Q ||
4210fa
-        Reason == RSA_R_D_E_NOT_CONGRUENT_TO_1) {
4210fa
-      return FALSE;
4210fa
-    }
4210fa
-  }
4210fa
-
4210fa
-  return TRUE;
4210fa
-}
4210fa
-
4210fa
-/**
4210fa
-  Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
4210fa
-
4210fa
-  This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
4210fa
-  RSA PKCS#1.
4210fa
-  If the Signature buffer is too small to hold the contents of signature, FALSE
4210fa
-  is returned and SigSize is set to the required buffer size to obtain the signature.
4210fa
-
4210fa
-  If RsaContext is NULL, then return FALSE.
4210fa
-  If MessageHash is NULL, then return FALSE.
4210fa
-  If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
4210fa
-  If SigSize is large enough but Signature is NULL, then return FALSE.
4210fa
-
4210fa
-  @param[in]       RsaContext   Pointer to RSA context for signature generation.
4210fa
-  @param[in]       MessageHash  Pointer to octet message hash to be signed.
4210fa
-  @param[in]       HashSize     Size of the message hash in bytes.
4210fa
-  @param[out]      Signature    Pointer to buffer to receive RSA PKCS1-v1_5 signature.
4210fa
-  @param[in, out]  SigSize      On input, the size of Signature buffer in bytes.
4210fa
-                                On output, the size of data returned in Signature buffer in bytes.
4210fa
-
4210fa
-  @retval  TRUE   Signature successfully generated in PKCS1-v1_5.
4210fa
-  @retval  FALSE  Signature generation failed.
4210fa
-  @retval  FALSE  SigSize is too small.
4210fa
-
4210fa
-**/
4210fa
-BOOLEAN
4210fa
-EFIAPI
4210fa
-RsaPkcs1Sign (
4210fa
-  IN      VOID         *RsaContext,
4210fa
-  IN      CONST UINT8  *MessageHash,
4210fa
-  IN      UINTN        HashSize,
4210fa
-  OUT     UINT8        *Signature,
4210fa
-  IN OUT  UINTN        *SigSize
4210fa
-  )
4210fa
-{
4210fa
-  RSA      *Rsa;
4210fa
-  UINTN    Size;
4210fa
-  INT32    DigestType;
4210fa
-
4210fa
-  //
4210fa
-  // Check input parameters.
4210fa
-  //
4210fa
-  if (RsaContext == NULL || MessageHash == NULL) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-
4210fa
-  Rsa = (RSA *) RsaContext;
4210fa
-  Size = BN_num_bytes (Rsa->n);
4210fa
-
4210fa
-  if (*SigSize < Size) {
4210fa
-    *SigSize = Size;
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-  
4210fa
-  if (Signature == NULL) {
4210fa
-    return FALSE;
4210fa
-  }
4210fa
-  
4210fa
-  //
4210fa
-  // Determine the message digest algorithm according to digest size.
4210fa
-  //   Only MD5, SHA-1 or SHA-256 algorithm is supported. 
4210fa
-  //
4210fa
-  switch (HashSize) {
4210fa
-  case MD5_DIGEST_SIZE:
4210fa
-    DigestType = NID_md5;
4210fa
-    break;
4210fa
-    
4210fa
-  case SHA1_DIGEST_SIZE:
4210fa
-    DigestType = NID_sha1;
4210fa
-    break;
4210fa
-    
4210fa
-  case SHA256_DIGEST_SIZE:
4210fa
-    DigestType = NID_sha256;
4210fa
-    break;
4210fa
-
4210fa
-  default:
4210fa
-    return FALSE;
4210fa
-  }  
4210fa
-
4210fa
-  return (BOOLEAN) RSA_sign (
4210fa
-                     DigestType,
4210fa
-                     MessageHash,
4210fa
-                     (UINT32) HashSize,
4210fa
-                     Signature,
4210fa
-                     (UINT32 *) SigSize,
4210fa
-                     (RSA *) RsaContext
4210fa
-                     );
4210fa
-}
4210fa
diff --git a/Cryptlib/update.sh b/Cryptlib/update.sh
4210fa
index 57b6631..0e34db9 100755
4210fa
--- a/Cryptlib/update.sh
4210fa
+++ b/Cryptlib/update.sh
4210fa
@@ -14,13 +14,10 @@ cp $DIR/Cipher/CryptTdes.c Cipher/CryptTdes.c
4210fa
 cp $DIR/Cipher/CryptArc4.c Cipher/CryptArc4.c
4210fa
 cp $DIR/Rand/CryptRand.c Rand/CryptRand.c
4210fa
 cp $DIR/Pk/CryptRsaBasic.c Pk/CryptRsaBasic.c
4210fa
-cp $DIR/Pk/CryptRsaExt.c Pk/CryptRsaExt.c
4210fa
 cp $DIR/Pk/CryptRsaExtNull.c Pk/CryptRsaExtNull.c
4210fa
-cp $DIR/Pk/CryptPkcs7Sign.c Pk/CryptPkcs7Sign.c
4210fa
 cp $DIR/Pk/CryptPkcs7SignNull.c Pk/CryptPkcs7SignNull.c
4210fa
 cp $DIR/Pk/CryptPkcs7Verify.c Pk/CryptPkcs7Verify.c
4210fa
-cp $DIR/Pk/CryptPkcs7VerifyNull.c Pk/CryptPkcs7VerifyNull.c
4210fa
-cp $DIR/Pk/CryptDh.c Pk/CryptDh.c
4210fa
+cp $DIR/Pk/CryptDhNull.c Pk/CryptDhNull.c
4210fa
 cp $DIR/Pk/CryptX509.c Pk/CryptX509.c
4210fa
 cp $DIR/Pk/CryptAuthenticode.c Pk/CryptAuthenticode.c
4210fa
 cp $DIR/Pem/CryptPem.c Pem/CryptPem.c
4210fa
-- 
4210fa
1.9.3
4210fa