]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLib/Cipher/CryptArc4.c
2 ARC4 Wrapper Implementation over OpenSSL.
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "InternalCryptLib.h"
16 #include <openssl/rc4.h>
19 Retrieves the size, in bytes, of the context buffer required for ARC4 operations.
21 @return The size, in bytes, of the context buffer required for ARC4 operations.
31 // Memory for 2 copies of RC4_KEY is allocated, one for working copy, and the other
32 // for backup copy. When Arc4Reset() is called, we can use the backup copy to restore
33 // the working copy to the initial state.
35 return (UINTN
) (2 * sizeof(RC4_KEY
));
39 Initializes user-supplied memory as ARC4 context for subsequent use.
41 This function initializes user-supplied memory pointed by Arc4Context as ARC4 context.
42 In addtion, it sets up all ARC4 key materials for subsequent encryption and decryption
45 If Arc4Context is NULL, then ASSERT().
46 If Key is NULL, then ASSERT().
47 If KeySize does not in the range of [5, 256] bytes, then ASSERT().
49 @param[out] Arc4Context Pointer to ARC4 context being initialized.
50 @param[in] Key Pointer to the user-supplied ARC4 key.
51 @param[in] KeySize Size of ARC4 key in bytes.
53 @retval TRUE ARC4 context initialization succeeded.
54 @retval FALSE ARC4 context initialization failed.
60 OUT VOID
*Arc4Context
,
67 ASSERT (Arc4Context
!= NULL
);
69 ASSERT ((KeySize
>= 5) && (KeySize
<= 256));
71 Rc4Key
= (RC4_KEY
*) Arc4Context
;
73 RC4_set_key (Rc4Key
, (UINT32
) KeySize
, Key
);
75 CopyMem (Rc4Key
+ 1, Rc4Key
, sizeof(RC4_KEY
));
81 Performs ARC4 encryption on a data buffer of the specified size.
83 This function performs ARC4 encryption on data buffer pointed by Input, of specified
85 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
86 invalid ARC4 context is undefined.
88 If Arc4Context is NULL, then ASSERT().
89 If Input is NULL, then ASSERT().
90 If Output is NULL, then ASSERT().
92 @param[in, out] Arc4Context Pointer to the ARC4 context.
93 @param[in] Input Pointer to the buffer containing the data to be encrypted.
94 @param[in] InputSize Size of the Input buffer in bytes.
95 @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.
97 @retval TRUE ARC4 encryption succeeded.
98 @retval FALSE ARC4 encryption failed.
104 IN OUT VOID
*Arc4Context
,
105 IN CONST UINT8
*Input
,
112 ASSERT (Arc4Context
!= NULL
);
113 ASSERT (Input
!= NULL
);
114 ASSERT (Output
!= NULL
);
116 Rc4Key
= (RC4_KEY
*) Arc4Context
;
118 RC4 (Rc4Key
, (UINT32
) InputSize
, Input
, Output
);
124 Performs ARC4 decryption on a data buffer of the specified size.
126 This function performs ARC4 decryption on data buffer pointed by Input, of specified
128 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
129 invalid ARC4 context is undefined.
131 If Arc4Context is NULL, then ASSERT().
132 If Input is NULL, then ASSERT().
133 If Output is NULL, then ASSERT().
135 @param[in, out] Arc4Context Pointer to the ARC4 context.
136 @param[in] Input Pointer to the buffer containing the data to be decrypted.
137 @param[in] InputSize Size of the Input buffer in bytes.
138 @param[out] Output Pointer to a buffer that receives the ARC4 decryption output.
140 @retval TRUE ARC4 decryption succeeded.
141 @retval FALSE ARC4 decryption failed.
147 IN OUT VOID
*Arc4Context
,
155 ASSERT (Arc4Context
!= NULL
);
156 ASSERT (Input
!= NULL
);
157 ASSERT (Output
!= NULL
);
159 Rc4Key
= (RC4_KEY
*) Arc4Context
;
161 RC4 (Rc4Key
, (UINT32
) InputSize
, Input
, Output
);
167 Resets the ARC4 context to the initial state.
169 The function resets the ARC4 context to the state it had immediately after the
170 ARC4Init() function call.
171 Contrary to ARC4Init(), Arc4Reset() requires no secret key as input, but ARC4 context
172 should be already correctly initialized by ARC4Init().
174 If Arc4Context is NULL, then ASSERT().
176 @param[in, out] Arc4Context Pointer to the ARC4 context.
178 @retval TRUE ARC4 reset succeeded.
179 @retval FALSE ARC4 reset failed.
185 IN OUT VOID
*Arc4Context
190 ASSERT (Arc4Context
!= NULL
);
192 Rc4Key
= (RC4_KEY
*) Arc4Context
;
194 CopyMem (Rc4Key
, Rc4Key
+ 1, sizeof(RC4_KEY
));