]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/IpSecDxe/IpSecCryptIo.c
Add NetworkPkg (P.UDK2010.UP3.Network.P1)
[mirror_edk2.git] / NetworkPkg / IpSecDxe / IpSecCryptIo.c
diff --git a/NetworkPkg/IpSecDxe/IpSecCryptIo.c b/NetworkPkg/IpSecDxe/IpSecCryptIo.c
new file mode 100644 (file)
index 0000000..7011f98
--- /dev/null
@@ -0,0 +1,133 @@
+/** @file\r
+  Common operation for Security.\r
+\r
+  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "IpSecCryptIo.h"\r
+//\r
+// Alogrithm's informations for the Encrypt/Decrpt Alogrithm.\r
+//\r
+ENCRYPT_ALGORITHM mIpsecEncryptAlgorithmList[IPSEC_ENCRYPT_ALGORITHM_LIST_SIZE] = {\r
+  {EFI_IPSEC_EALG_NULL, 0, 0, 1, NULL, NULL, NULL, NULL},\r
+  {(UINT8)-1,           0, 0, 0, NULL, NULL, NULL, NULL}\r
+};\r
+//\r
+// Alogrithm's informations for the Authentication algorithm\r
+//\r
+AUTH_ALGORITHM mIpsecAuthAlgorithmList[IPSEC_AUTH_ALGORITHM_LIST_SIZE] = {\r
+  {EFI_IPSEC_AALG_NONE, 0, 0, 0, NULL, NULL, NULL, NULL},\r
+  {EFI_IPSEC_AALG_NULL, 0, 0, 0, NULL, NULL, NULL, NULL},\r
+  {(UINT8)-1,           0, 0, 0, NULL, NULL, NULL, NULL}\r
+};\r
+\r
+\r
+/**\r
+  Get the block size of encrypt alogrithm. The block size is based on the algorithm used.\r
+\r
+  @param[in]  AlgorithmId          The encrypt algorithm ID.\r
+\r
+  @return The value of block size.\r
+\r
+**/\r
+UINTN\r
+IpSecGetEncryptBlockSize (\r
+  IN UINT8   AlgorithmId\r
+  )\r
+{\r
+  UINT8 Index;\r
+\r
+  for (Index = 0; Index < IPSEC_ENCRYPT_ALGORITHM_LIST_SIZE; Index++) {\r
+    if (AlgorithmId == mIpsecEncryptAlgorithmList[Index].AlgorithmId) {\r
+      //\r
+      // The BlockSize is same with IvSize.\r
+      //\r
+      return mIpsecEncryptAlgorithmList[Index].BlockSize;\r
+    }\r
+  }\r
+\r
+  return (UINTN) -1;\r
+}\r
+\r
+/**\r
+  Get the IV size of encrypt alogrithm. The IV size is based on the algorithm used.\r
+\r
+  @param[in]  AlgorithmId          The encrypt algorithm ID.\r
+\r
+  @return The value of IV size.\r
+\r
+**/\r
+UINTN\r
+IpSecGetEncryptIvLength (\r
+  IN UINT8 AlgorithmId\r
+  )\r
+{\r
+  UINT8 Index;\r
+\r
+  for (Index = 0; Index < IPSEC_ENCRYPT_ALGORITHM_LIST_SIZE; Index++) {\r
+    if (AlgorithmId == mIpsecEncryptAlgorithmList[Index].AlgorithmId) {\r
+      //\r
+      // The BlockSize is same with IvSize.\r
+      //\r
+      return mIpsecEncryptAlgorithmList[Index].IvLength;\r
+    }\r
+  }\r
+\r
+  return (UINTN) -1;\r
+}\r
+\r
+/**\r
+  Get the ICV size of Authenticaion alogrithm. The ICV size is based on the algorithm used.\r
+\r
+  @param[in]  AuthAlgorithmId          The Authentication algorithm ID.\r
+\r
+  @return The value of ICV size.\r
+\r
+**/\r
+UINTN\r
+IpSecGetIcvLength (\r
+  IN UINT8  AuthAlgorithmId\r
+  )\r
+{\r
+  UINT8 Index;\r
+  for (Index = 0; Index < IPSEC_AUTH_ALGORITHM_LIST_SIZE; Index++) {\r
+    if (AuthAlgorithmId == mIpsecAuthAlgorithmList[Index].AlgorithmId) {\r
+      return mIpsecAuthAlgorithmList[Index].IcvLength;\r
+    }\r
+  }\r
+  return (UINTN) -1;\r
+}\r
+\r
+/**\r
+  Generate a random data for IV. If the IvSize is zero, not needed to create\r
+  IV and return EFI_SUCCESS.\r
+\r
+  @param[in]  IvBuffer  The pointer of the IV buffer.\r
+  @param[in]  IvSize    The IV size.\r
+\r
+  @retval     EFI_SUCCESS  Create a random data for IV.\r
+\r
+**/\r
+EFI_STATUS\r
+IpSecGenerateIv (\r
+  IN UINT8                           *IvBuffer,\r
+  IN UINTN                           IvSize\r
+  )\r
+{\r
+  if (IvSize != 0) {\r
+    //\r
+    //TODO: return CryptGenerateRandom (IvBuffer, IvSize);\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r