89#define SWAP_BITS_WITHIN_UINT32( _value, _shift, _mask ) \
92 _tmp = ((_value) ^ ((_value) >> (_shift))) & (_mask ); \
93 _value = (_value) ^ _tmp ^ (_tmp << (_shift)); \
102#define SWAP_BITS_BETWEEN_UINT32( _v1, _v2, _shift, _mask ) \
105 _tmp = ((_v1) ^ ((_v2) >> (_shift))) & (_mask); \
107 _v2 ^= (_tmp << (_shift )); \
114static const BYTE SymCryptDesDoubleShift[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
135 return SYMCRYPT_WRONG_KEY_SIZE;
233 Dr = (Dr & 0x00ffffff) | ((Cr & 0xf0000000 ) >> 4 );
234 Cr = (Cr & 0x0fffffff);
236 for(
r = 0;
r < 16;
r++)
242 if( SymCryptDesDoubleShift[
r ] ) {
243 Cr = ((Cr >> 2) | (Cr << 26));
244 Dr = ((Dr >> 2) | (Dr << 26));
246 Cr = ((Cr >> 1) | (Cr << 27));
247 Dr = ((Dr >> 1) | (Dr << 27));
259 K1 = SymCryptDesKeySelect[0][ (Cr )&0x3f ] |
260 SymCryptDesKeySelect[1][((Cr >> 6)&0x03) | ((Cr >> 7)&0x3c)] |
261 SymCryptDesKeySelect[2][((Cr >> 13)&0x0f) | ((Cr >> 14)&0x30)] |
262 SymCryptDesKeySelect[3][((Cr >> 20)&0x01) | ((Cr >> 21)&0x06) | ((Cr >> 22)&0x38)];
264 K2 = SymCryptDesKeySelect[4][ (Dr )&0x3f ] |
265 SymCryptDesKeySelect[5][((Dr >> 7)&0x03) | ((Dr >> 8)&0x3c)] |
266 SymCryptDesKeySelect[6][ (Dr >> 15)&0x3f ] |
267 SymCryptDesKeySelect[7][((Dr >> 21)&0x0f) | ((Dr >> 22)&0x30)];
283 tmp = ((
K2 << 16) | (
K1 & 0x0000ffff)) ;
284 expandedKeyTable[
r][0] = ROL32(tmp, 2);
286 tmp = ((
K1 >> 16) | (
K2 & 0xffff0000));
287 expandedKeyTable[
r][1] = ROL32(tmp, 6);
305 return SYMCRYPT_WRONG_KEY_SIZE;
318 keyIndex = (keyIndex + 8) %
cbKey;
323 return SYMCRYPT_NO_ERROR;
335#define F(L, R, keyptr) { \
336 Ta = keyptr[0] ^ R; \
337 Tb = keyptr[1] ^ R; \
339 L ^= *(UINT32 *)((PBYTE)SymCryptDesSpbox[0] + ( Ta & 0xfc)); \
340 L ^= *(UINT32 *)((PBYTE)SymCryptDesSpbox[1] + ( Tb & 0xfc)); \
341 L ^= *(UINT32 *)((PBYTE)SymCryptDesSpbox[2] + ((Ta>> 8)& 0xfc)); \
342 L ^= *(UINT32 *)((PBYTE)SymCryptDesSpbox[3] + ((Tb>> 8)& 0xfc)); \
343 L ^= *(UINT32 *)((PBYTE)SymCryptDesSpbox[4] + ((Ta>>16)& 0xfc)); \
344 L ^= *(UINT32 *)((PBYTE)SymCryptDesSpbox[5] + ((Tb>>16)& 0xfc)); \
345 L ^= *(UINT32 *)((PBYTE)SymCryptDesSpbox[6] + ((Ta>>24)& 0xfc)); \
346 L ^= *(UINT32 *)((PBYTE)SymCryptDesSpbox[7] + ((Tb>>24)& 0xfc)); }
384 Ta = (
L ^
R) & 0xf0f0f0f0;
389 Ta = (
L ^
R) & 0xfff0000f;
394 Ta = (
L ^
R) & 0x33333333;
399 Ta = (
L ^
R) & 0x03fc03fc;
404 Ta = (
L ^
R) & 0xaaaaaaaa;
413 for(
r=0;
r<16;
r += 2 )
423 for(
r=14;
r>=0;
r -= 2 )
432 for(
r=0;
r<16;
r += 2 )
439 Ta = (
L ^
R) & 0xaaaaaaaa;
444 Ta = (
L ^
R) & 0x03fc03fc;
449 Ta = (
L ^
R) & 0x33333333;
454 Ta = (
L ^
R) & 0xfff0000f;
459 Ta = (
L ^
R) & 0xf0f0f0f0;
492 Ta = (
L ^
R) & 0xf0f0f0f0;
497 Ta = (
L ^
R) & 0xfff0000f;
502 Ta = (
L ^
R) & 0x33333333;
507 Ta = (
L ^
R) & 0x03fc03fc;
512 Ta = (
L ^
R) & 0xaaaaaaaa;
520 for(
r=14;
r>=0;
r -= 2 )
527 for(
r=0;
r<16;
r += 2 )
534 for(
r=14;
r>=0;
r -= 2 )
543 Ta = (
L ^
R) & 0xaaaaaaaa;
548 Ta = (
L ^
R) & 0x03fc03fc;
553 Ta = (
L ^
R) & 0x33333333;
558 Ta = (
L ^
R) & 0xfff0000f;
563 Ta = (
L ^
R) & 0xf0f0f0f0;
604 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
605 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01,
606 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23,
610 0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
614 0x31, 0x4F, 0x83, 0x27, 0xFA, 0x7A, 0x09, 0xA8,
618 0x3F, 0xA4, 0x0E, 0x8A, 0x98, 0x4D, 0x48, 0x15,
703static unsigned BYTE ip[] = {
704 58, 50, 42, 34, 26, 18, 10, 2,
705 60, 52, 44, 36, 28, 20, 12, 4,
706 62, 54, 46, 38, 30, 22, 14, 6,
707 64, 56, 48, 40, 32, 24, 16, 8,
708 57, 49, 41, 33, 25, 17, 9, 1,
709 59, 51, 43, 35, 27, 19, 11, 3,
710 61, 53, 45, 37, 29, 21, 13, 5,
711 63, 55, 47, 39, 31, 23, 15, 7
715static unsigned BYTE fp[] = {
716 40, 8, 48, 16, 56, 24, 64, 32,
717 39, 7, 47, 15, 55, 23, 63, 31,
718 38, 6, 46, 14, 54, 22, 62, 30,
719 37, 5, 45, 13, 53, 21, 61, 29,
720 36, 4, 44, 12, 52, 20, 60, 28,
721 35, 3, 43, 11, 51, 19, 59, 27,
722 34, 2, 42, 10, 50, 18, 58, 26,
723 33, 1, 41, 9, 49, 17, 57, 25
727static unsigned BYTE ei[] = {
730 8, 9, 10, 11, 12, 13,
731 12, 13, 14, 15, 16, 17,
732 16, 17, 18, 19, 20, 21,
733 20, 21, 22, 23, 24, 25,
734 24, 25, 26, 27, 28, 29,
735 28, 29, 30, 31, 32, 1
741 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
742 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
743 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
744 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13,
747 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
748 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
749 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
750 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9,
753 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
754 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
755 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
756 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12,
759 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
760 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
761 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
762 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14,
765 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
766 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
767 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
768 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3,
771 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
772 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
773 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
774 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13,
777 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
778 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
779 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
780 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12,
783 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
784 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
785 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
786 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11
790static unsigned BYTE p32i[] = {
803 57, 49, 41, 33, 25, 17, 9,
804 1, 58, 50, 42, 34, 26, 18,
805 10, 2, 59, 51, 43, 35, 27,
806 19, 11, 3, 60, 52, 44, 36,
808 63, 55, 47, 39, 31, 23, 15,
809 7, 62, 54, 46, 38, 30, 22,
810 14, 6, 61, 53, 45, 37, 29,
811 21, 13, 5, 28, 20, 12, 4
816 1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28
821 14, 17, 11, 24, 1, 5,
822 3, 28, 15, 6, 21, 10,
823 23, 19, 12, 4, 26, 8,
824 16, 7, 27, 20, 13, 2,
825 41, 52, 31, 37, 47, 55,
826 30, 40, 51, 45, 33, 48,
827 44, 49, 39, 56, 34, 53,
828 46, 42, 50, 36, 29, 32
static const BYTE des3KnownCiphertext[8]
static const BYTE SP800_67Key[24]
const PCSYMCRYPT_BLOCKCIPHER SymCrypt3DesBlockCipher
VOID SYMCRYPT_CALL SymCrypt3DesCbcDecrypt(_In_ PCSYMCRYPT_3DES_EXPANDED_KEY pExpandedKey, _Inout_updates_(SYMCRYPT_3DES_BLOCK_SIZE) PBYTE pbChainingValue, _In_reads_(cbData) PCBYTE pbSrc, _Out_writes_(cbData) PBYTE pbDst, SIZE_T cbData)
VOID SYMCRYPT_CALL SymCrypt3DesCbcEncrypt(_In_ PCSYMCRYPT_3DES_EXPANDED_KEY pExpandedKey, _Inout_updates_(SYMCRYPT_3DES_BLOCK_SIZE) PBYTE pbChainingValue, _In_reads_(cbData) PCBYTE pbSrc, _Out_writes_(cbData) PBYTE pbDst, SIZE_T cbData)
VOID SYMCRYPT_CALL SymCryptDesSetOddParity(_Inout_updates_(cbData) PBYTE pbData, _In_ SIZE_T cbData)
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)
SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptDesExpandKey(_Out_ PSYMCRYPT_DES_EXPANDED_KEY pExpandedKey, _In_reads_(cbKey) PCBYTE pbKey, SIZE_T cbKey)
SYMCRYPT_NOINLINE VOID SYMCRYPT_CALL SymCrypt3DesEncrypt(_In_ PCSYMCRYPT_3DES_EXPANDED_KEY pExpandedKey, _In_reads_(SYMCRYPT_3DES_BLOCK_SIZE) PCBYTE pbSrc, _Out_writes_(SYMCRYPT_3DES_BLOCK_SIZE) PBYTE pbDst)
VOID SYMCRYPT_CALL SymCryptDesExpandSingleKey(_Out_writes_bytes_(128) UINT32 expandedKeyTable[16][2], _In_reads_(8) PCBYTE pKey)
#define SWAP_BITS_WITHIN_UINT32(_value, _shift, _mask)
const SYMCRYPT_BLOCKCIPHER SymCrypt3DesBlockCipher_default
SYMCRYPT_NOINLINE SYMCRYPT_ERROR SYMCRYPT_CALL SymCrypt3DesExpandKey(_Out_ PSYMCRYPT_3DES_EXPANDED_KEY pExpandedKey, _In_reads_(cbKey) PCBYTE pbKey, SIZE_T cbKey)
VOID SYMCRYPT_CALL SymCryptDesSelftest(void)
static const BYTE desKnownCiphertext[8]
const SYMCRYPT_BLOCKCIPHER SymCryptDesBlockCipher_default
static const BYTE des3KnownPlaintext[8]
SYMCRYPT_NOINLINE VOID SYMCRYPT_CALL SymCrypt3DesDecrypt(_In_ PCSYMCRYPT_3DES_EXPANDED_KEY pExpandedKey, _In_reads_(SYMCRYPT_3DES_BLOCK_SIZE) PCBYTE pbSrc, _Out_writes_(SYMCRYPT_3DES_BLOCK_SIZE) PBYTE pbDst)
#define SWAP_BITS_BETWEEN_UINT32(_v1, _v2, _shift, _mask)
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)
const PCSYMCRYPT_BLOCKCIPHER SymCryptDesBlockCipher
VOID SYMCRYPT_CALL SymCrypt3DesSelftest(void)
static void sbox(unsigned char *dst, const unsigned char *src)
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
GLdouble GLdouble GLdouble r
GLboolean GLboolean GLboolean b
GLenum GLuint GLenum GLsizei const GLchar * buf
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define _Inout_updates_(s)
#define _Out_writes_bytes_(s)
VOID SYMCRYPT_CALL SymCryptInjectError(PBYTE pbData, SIZE_T cbData)
static const unsigned char totrot[16]
static const unsigned char pc1[56]
static const unsigned char pc2[48]
#define SYMCRYPT_ASSERT(_x)
VOID SYMCRYPT_CALL SymCryptCbcEncrypt(_In_ PCSYMCRYPT_BLOCKCIPHER pBlockCipher, _In_ PCVOID pExpandedKey, _Inout_updates_(pBlockCipher->blockSize) PBYTE pbChainingValue, _In_reads_(cbData) PCBYTE pbSrc, _Out_writes_(cbData) PBYTE pbDst, SIZE_T cbData)
#define SYMCRYPT_DES_BLOCK_SIZE
_Analysis_noreturn_ VOID SYMCRYPT_CALL SymCryptFatal(UINT32 fatalCode)
#define SYMCRYPT_3DES_BLOCK_SIZE
#define SYMCRYPT_LOAD_LSBFIRST32(p)
#define SYMCRYPT_STORE_LSBFIRST32(p, v)
VOID SYMCRYPT_CALL SymCryptCbcDecrypt(_In_ PCSYMCRYPT_BLOCKCIPHER pBlockCipher, _In_ PCVOID pExpandedKey, _Inout_updates_(pBlockCipher->blockSize) PBYTE pbChainingValue, _In_reads_(cbData) PCBYTE pbSrc, _Out_writes_(cbData) PBYTE pbDst, SIZE_T cbData)
SYMCRYPT_MAGIC_FIELD * PSYMCRYPT_3DES_EXPANDED_KEY
#define SYMCRYPT_ALIGN_AT(alignment)
const SYMCRYPT_DES_EXPANDED_KEY * PCSYMCRYPT_DES_EXPANDED_KEY
* PSYMCRYPT_DES_EXPANDED_KEY
PCBYTE PBYTE SIZE_T cbData
#define SYMCRYPT_SET_MAGIC(p)
SYMCRYPT_DES_EXPANDED_KEY
SYMCRYPT_MAGIC_FIELD SYMCRYPT_3DES_EXPANDED_KEY
const SYMCRYPT_3DES_EXPANDED_KEY * PCSYMCRYPT_3DES_EXPANDED_KEY
PCSYMCRYPT_HMAC_MD5_EXPANDED_KEY pKey
#define SYMCRYPT_CHECK_MAGIC(p)