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

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