ReactOS 0.4.17-dev-1005-g171e1de
desx.c
Go to the documentation of this file.
1//
2// DesX.c DESX implementation
3//
4// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
5//
6
7
8#include "precomp.h"
9
10
12 SymCryptDesxExpandKey, // PSYMCRYPT_BLOCKCIPHER_EXPAND_KEY expandKeyFunc;
13 SymCryptDesxEncrypt, // PSYMCRYPT_BLOCKCIPHER_CRYPT encryptFunc;
14 SymCryptDesxDecrypt, // PSYMCRYPT_BLOCKCIPHER_CRYPT decryptFunc;
15 NULL, // PSYMCRYPT_BLOCKCIPHER_CRYPT_ECB ecbEncryptFunc;
16 NULL, // PSYMCRYPT_BLOCKCIPHER_CRYPT_ECB ecbDecryptFunc;
17 NULL, // PSYMCRYPT_BLOCKCIPHER_CRYPT_MODE cbcEncryptFunc;
18 NULL, // PSYMCRYPT_BLOCKCIPHER_CRYPT_MODE cbcDecryptFunc;
19 NULL, // PSYMCRYPT_BLOCKCIPHER_MAC_MODE cbcMacFunc;
20 NULL, // PSYMCRYPT_BLOCKCIPHER_CRYPT_MODE ctrMsbFunc;
21 NULL, // PSYMCRYPT_BLOCKCIPHER_AEADPART_MODE gcmEncryptPartFunc;
22 NULL, // PSYMCRYPT_BLOCKCIPHER_AEADPART_MODE gcmDecryptPartFunc;
23 8, // SIZE_T blockSize;
24 sizeof( SYMCRYPT_DESX_EXPANDED_KEY ), // SIZE_T expandedKeySize; // = sizeof( SYMCRYPT_XXX_EXPANDED_KEY )
25};
26
28
34{
35 if( cbKey != 24 )
36 {
37 return SYMCRYPT_WRONG_KEY_SIZE;
38 }
39
41 memcpy( pExpandedKey->inputWhitening, pbKey+8, 8 );
42 memcpy( pExpandedKey->outputWhitening, pbKey+16, 8 );
43
44 return SYMCRYPT_NO_ERROR;
45}
46
47VOID
53{
55
56 //
57 // We buffer the result locally to obey the read once/write once rule.
58 //
59 SymCryptXorBytes( pbSrc, pExpandedKey->inputWhitening, buf, 8 );
61 SymCryptXorBytes( buf, pExpandedKey->outputWhitening, pbDst, 8 );
62
63 SymCryptWipeKnownSize( buf, sizeof( buf ) );
64}
65
66VOID
72{
74
75 //
76 // We buffer the result locally to obey the read once/write once rule.
77 //
78 SymCryptXorBytes( pbSrc, pExpandedKey->outputWhitening, buf, 8 );
80 SymCryptXorBytes( buf, pExpandedKey->inputWhitening, pbDst, 8 );
81
82 SymCryptWipeKnownSize( buf, sizeof( buf ) );
83}
84
85
86static const BYTE desxKnownKey[24] = {
87 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
88 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
89 0x01, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18
90};
91
92static const BYTE desxKnownPlaintext[] = {
93 0xd9, 0xb6, 0xa1, 0x4e, 0xe6, 0x71, 0x4e, 0x17
94};
95
96static const BYTE desxKnownCiphertext[] = {
97 0x66, 0x77, 0x1f, 0x2a, 0x0c, 0x05, 0x01, 0xca
98};
99
100
101VOID
104{
107
108 if( SymCryptDesxExpandKey( &key, desxKnownKey, sizeof( desxKnownKey )) != SYMCRYPT_NO_ERROR )
109 {
110 SymCryptFatal( 'desx' );
111 }
112
114
116
118 {
119 SymCryptFatal( 'desy' );
120 }
121
123
125
127 {
128 SymCryptFatal( 'desz' );
129 }
130
131}
VOID SYMCRYPT_CALL SymCryptDesxSelftest(void)
Definition: desx.c:103
const PCSYMCRYPT_BLOCKCIPHER SymCryptDesxBlockCipher
Definition: desx.c:27
VOID SYMCRYPT_CALL SymCryptDesxEncrypt(_In_ PCSYMCRYPT_DESX_EXPANDED_KEY pExpandedKey, _In_reads_(SYMCRYPT_DESX_BLOCK_SIZE) PCBYTE pbSrc, _Out_writes_(SYMCRYPT_DESX_BLOCK_SIZE) PBYTE pbDst)
Definition: desx.c:49
static const BYTE desxKnownPlaintext[]
Definition: desx.c:92
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptDesxExpandKey(_Out_ PSYMCRYPT_DESX_EXPANDED_KEY pExpandedKey, _In_reads_(cbKey) PCBYTE pbKey, SIZE_T cbKey)
Definition: desx.c:31
static const BYTE desxKnownCiphertext[]
Definition: desx.c:96
const SYMCRYPT_BLOCKCIPHER SymCryptDesxBlockCipher_default
Definition: desx.c:11
VOID SYMCRYPT_CALL SymCryptDesxDecrypt(_In_ PCSYMCRYPT_DESX_EXPANDED_KEY pExpandedKey, _In_reads_(SYMCRYPT_DESX_BLOCK_SIZE) PCBYTE pbSrc, _Out_writes_(SYMCRYPT_DESX_BLOCK_SIZE) PBYTE pbDst)
Definition: desx.c:68
static const BYTE desxKnownKey[24]
Definition: desx.c:86
#define NULL
Definition: types.h:112
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define _In_reads_(s)
Definition: no_sal2.h:168
#define _Out_writes_(s)
Definition: no_sal2.h:176
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
BYTE * PBYTE
Definition: pedump.c:66
VOID SYMCRYPT_CALL SymCryptInjectError(PBYTE pbData, SIZE_T cbData)
Definition: copy.c:22
VOID SYMCRYPT_CALL SymCryptDesEncrypt(_In_ PCSYMCRYPT_DES_EXPANDED_KEY pExpandedKey, _In_reads_(SYMCRYPT_DES_BLOCK_SIZE) PCBYTE pbSrc, _Out_writes_(SYMCRYPT_DES_BLOCK_SIZE) PBYTE pbDst)
Definition: 3des.c:142
FORCEINLINE VOID SYMCRYPT_CALL SymCryptWipeKnownSize(_Out_writes_bytes_(cbData) PVOID pbData, SIZE_T cbData)
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptDesExpandKey(_Out_ PSYMCRYPT_DES_EXPANDED_KEY pExpandedKey, _In_reads_(cbKey) PCBYTE pbKey, SIZE_T cbKey)
Definition: 3des.c:124
_Analysis_noreturn_ VOID SYMCRYPT_CALL SymCryptFatal(UINT32 fatalCode)
VOID SYMCRYPT_CALL SymCryptXorBytes(_In_reads_(cbBytes) PCBYTE pbSrc1, _In_reads_(cbBytes) PCBYTE pbSrc2, _Out_writes_(cbBytes) PBYTE pbResult, SIZE_T cbBytes)
Definition: libmain.c:236
VOID SYMCRYPT_CALL SymCryptDesDecrypt(_In_ PCSYMCRYPT_DES_EXPANDED_KEY pExpandedKey, _In_reads_(SYMCRYPT_DES_BLOCK_SIZE) PCBYTE pbSrc, _Out_writes_(SYMCRYPT_DES_BLOCK_SIZE) PBYTE pbDst)
Definition: 3des.c:152
#define SYMCRYPT_DESX_BLOCK_SIZE
Definition: symcrypt.h:4500
SYMCRYPT_ERROR
Definition: symcrypt.h:227
#define SYMCRYPT_ALIGN
PCBYTE pbSrc
* PSYMCRYPT_DESX_EXPANDED_KEY
#define SYMCRYPT_CALL
PCBYTE pbKey
PCBYTE SIZE_T cbKey
PCBYTE PBYTE pbDst
const SYMCRYPT_DESX_EXPANDED_KEY * PCSYMCRYPT_DESX_EXPANDED_KEY
const BYTE * PCBYTE
SYMCRYPT_DESX_EXPANDED_KEY
PCVOID pExpandedKey
ULONG_PTR SIZE_T
Definition: typedefs.h:80
unsigned char BYTE
Definition: xxhash.c:193