]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLib/Cipher/CryptArc4.c
2 ARC4 Wrapper Implementation over OpenSSL.
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "InternalCryptLib.h"
10 #include <openssl/rc4.h>
13 Retrieves the size, in bytes, of the context buffer required for ARC4 operations.
15 @return The size, in bytes, of the context buffer required for ARC4 operations.
25 // Memory for 2 copies of RC4_KEY is allocated, one for working copy, and the other
26 // for backup copy. When Arc4Reset() is called, we can use the backup copy to restore
27 // the working copy to the initial state.
29 return (UINTN
) (2 * sizeof (RC4_KEY
));
33 Initializes user-supplied memory as ARC4 context for subsequent use.
35 This function initializes user-supplied memory pointed by Arc4Context as ARC4 context.
36 In addition, it sets up all ARC4 key materials for subsequent encryption and decryption
39 If Arc4Context is NULL, then return FALSE.
40 If Key is NULL, then return FALSE.
41 If KeySize does not in the range of [5, 256] bytes, then return FALSE.
43 @param[out] Arc4Context Pointer to ARC4 context being initialized.
44 @param[in] Key Pointer to the user-supplied ARC4 key.
45 @param[in] KeySize Size of ARC4 key in bytes.
47 @retval TRUE ARC4 context initialization succeeded.
48 @retval FALSE ARC4 context initialization failed.
54 OUT VOID
*Arc4Context
,
62 // Check input parameters.
64 if (Arc4Context
== NULL
|| Key
== NULL
|| (KeySize
< 5 || KeySize
> 256)) {
68 Rc4Key
= (RC4_KEY
*) Arc4Context
;
70 RC4_set_key (Rc4Key
, (UINT32
) KeySize
, Key
);
72 CopyMem (Rc4Key
+ 1, Rc4Key
, sizeof (RC4_KEY
));
78 Performs ARC4 encryption on a data buffer of the specified size.
80 This function performs ARC4 encryption on data buffer pointed by Input, of specified
82 Arc4Context should be already correctly initialized by Arc4Init(). Behavior with
83 invalid ARC4 context is undefined.
85 If Arc4Context is NULL, then return FALSE.
86 If Input is NULL, then return FALSE.
87 If Output is NULL, then return FALSE.
89 @param[in, out] Arc4Context Pointer to the ARC4 context.
90 @param[in] Input Pointer to the buffer containing the data to be encrypted.
91 @param[in] InputSize Size of the Input buffer in bytes.
92 @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.
94 @retval TRUE ARC4 encryption succeeded.
95 @retval FALSE ARC4 encryption failed.
101 IN OUT VOID
*Arc4Context
,
102 IN CONST UINT8
*Input
,
110 // Check input parameters.
112 if (Arc4Context
== NULL
|| Input
== NULL
|| Output
== NULL
|| InputSize
> INT_MAX
) {
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 return FALSE.
132 If Input is NULL, then return FALSE.
133 If Output is NULL, then return FALSE.
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
,
156 // Check input parameters.
158 if (Arc4Context
== NULL
|| Input
== NULL
|| Output
== NULL
|| InputSize
> INT_MAX
) {
162 Rc4Key
= (RC4_KEY
*) Arc4Context
;
164 RC4 (Rc4Key
, (UINT32
) InputSize
, Input
, Output
);
170 Resets the ARC4 context to the initial state.
172 The function resets the ARC4 context to the state it had immediately after the
173 ARC4Init() function call.
174 Contrary to ARC4Init(), Arc4Reset() requires no secret key as input, but ARC4 context
175 should be already correctly initialized by ARC4Init().
177 If Arc4Context is NULL, then return FALSE.
179 @param[in, out] Arc4Context Pointer to the ARC4 context.
181 @retval TRUE ARC4 reset succeeded.
182 @retval FALSE ARC4 reset failed.
188 IN OUT VOID
*Arc4Context
194 // Check input parameters.
196 if (Arc4Context
== NULL
) {
200 Rc4Key
= (RC4_KEY
*) Arc4Context
;
202 CopyMem (Rc4Key
, Rc4Key
+ 1, sizeof (RC4_KEY
));