]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLib/Hash/CryptXkcp.c
2 Encode realted functions from Xkcp.
4 Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
7 Copyright 2022 The eXtended Keccak Code Package (XKCP)
8 https://github.com/XKCP/XKCP
9 Keccak, designed by Guido Bertoni, Joan Daemen, Michael Peeters and Gilles Van Assche.
10 Implementation by the designers, hereby denoted as "the implementer".
11 For more information, feedback or questions, please refer to the Keccak Team website:
13 To the extent possible under law, the implementer has waived all copyright
14 and related or neighboring rights to the source code in this file.
15 http://creativecommons.org/publicdomain/zero/1.0/
19 #include "CryptParallelHash.h"
22 Encode function from XKCP.
24 Encodes the input as a byte string in a way that can be unambiguously parsed
25 from the beginning of the string by inserting the length of the byte string
26 before the byte string representation of input.
28 @param[out] EncBuf Result of left encode.
29 @param[in] Value Input of left encode.
31 @retval EncLen Size of encode result in bytes.
45 for ( ValueCopy
= Value
, BlockNum
= 0; ValueCopy
&& (BlockNum
< sizeof (UINTN
)); ++BlockNum
, ValueCopy
>>= 8 ) {
55 for (Index
= 1; Index
<= BlockNum
; ++Index
) {
56 EncBuf
[Index
] = (UINT8
)(Value
>> (8 * (BlockNum
- Index
)));
59 EncBuf
[0] = (UINT8
)BlockNum
;
60 EncLen
= BlockNum
+ 1;
66 Encode function from XKCP.
68 Encodes the input as a byte string in a way that can be unambiguously parsed
69 from the end of the string by inserting the length of the byte string after
70 the byte string representation of input.
72 @param[out] EncBuf Result of right encode.
73 @param[in] Value Input of right encode.
75 @retval EncLen Size of encode result in bytes.
89 for (ValueCopy
= Value
, BlockNum
= 0; ValueCopy
&& (BlockNum
< sizeof (UINTN
)); ++BlockNum
, ValueCopy
>>= 8) {
99 for (Index
= 1; Index
<= BlockNum
; ++Index
) {
100 EncBuf
[Index
-1] = (UINT8
)(Value
>> (8 * (BlockNum
-Index
)));
103 EncBuf
[BlockNum
] = (UINT8
)BlockNum
;
104 EncLen
= BlockNum
+ 1;