37 * This version is designed for flexibility and speed using operations on
38 * 32-bit words rather than operations on bytes. It can be compiled with
39 * either big or little endian internal byte order but is faster when the
40 * native byte order for the processor is used.
41 *
42 * THE CIPHER INTERFACE
43 *
44 * The cipher interface is implemented as an array of bytes in which lower
45 * AES bit sequence indexes map to higher numeric significance within bytes.
46 */
47
48 /*
49 * OpenSolaris changes
50 * 1. Added __cplusplus and _AESTAB_H header guards
51 * 2. Added header files sys/types.h and aes_impl.h
52 * 3. Added defines for AES_ENCRYPT, AES_DECRYPT, AES_REV_DKS, and ASM_AMD64_C
53 * 4. Moved defines for IS_BIG_ENDIAN, IS_LITTLE_ENDIAN, PLATFORM_BYTE_ORDER
54 * from brg_endian.h
55 * 5. Undefined VIA_ACE_POSSIBLE and ASSUME_VIA_ACE_PRESENT
56 * 6. Changed uint_8t and uint_32t to uint8_t and uint32_t
57 * 7. cstyled and hdrchk code
58 *
59 */
60
61 #ifndef _AESOPT_H
62 #define _AESOPT_H
63
64 #pragma ident "%Z%%M% %I% %E% SMI"
65
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69
70 #include <sys/types.h>
71 #include <aes_impl.h>
72
73 /* SUPPORT FEATURES */
74 #define AES_ENCRYPT /* if support for encryption is needed */
75 #define AES_DECRYPT /* if support for decryption is needed */
76
77 /* PLATFORM-SPECIFIC FEATURES */
78 #define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */
79 #define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */
80 #define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
81 #define AES_REV_DKS /* define to reverse decryption key schedule */
82
83
84 /*
85 * CONFIGURATION - THE USE OF DEFINES
86 * Later in this section there are a number of defines that control the
87 * operation of the code. In each section, the purpose of each define is
88 * explained so that the relevant form can be included or excluded by
89 * setting either 1's or 0's respectively on the branches of the related
90 * #if clauses. The following local defines should not be changed.
504 #endif
505
506 #if ENC_ROUND == NO_TABLES && ENC_UNROLL != NONE
507 #undef ENC_UNROLL
508 #define ENC_UNROLL NONE
509 #endif
510
511 #if DEC_ROUND == NO_TABLES && LAST_DEC_ROUND != NO_TABLES
512 #undef LAST_DEC_ROUND
513 #define LAST_DEC_ROUND NO_TABLES
514 #elif DEC_ROUND == ONE_TABLE && LAST_DEC_ROUND == FOUR_TABLES
515 #undef LAST_DEC_ROUND
516 #define LAST_DEC_ROUND ONE_TABLE
517 #endif
518
519 #if DEC_ROUND == NO_TABLES && DEC_UNROLL != NONE
520 #undef DEC_UNROLL
521 #define DEC_UNROLL NONE
522 #endif
523
524 #if defined(bswap32)
525 #define aes_sw32 bswap32
526 #elif defined(bswap_32)
527 #define aes_sw32 bswap_32
528 #else
529 #define brot(x, n) (((uint32_t)(x) << n) | ((uint32_t)(x) >> (32 - n)))
530 #define aes_sw32(x) ((brot((x), 8) & 0x00ff00ff) | (brot((x), 24) & 0xff00ff00))
531 #endif
532
533 /*
534 * upr(x, n): rotates bytes within words by n positions, moving bytes to
535 * higher index positions with wrap around into low positions
536 * ups(x, n): moves bytes by n positions to higher index positions in
537 * words but without wrap around
538 * bval(x, n): extracts a byte from a word
539 *
540 * WARNING: The definitions given here are intended only for use with
541 * unsigned variables and with shift counts that are compile
542 * time constants
543 */
544
545 #if (ALGORITHM_BYTE_ORDER == IS_LITTLE_ENDIAN)
546 #define upr(x, n) (((uint32_t)(x) << (8 * (n))) | \
547 ((uint32_t)(x) >> (32 - 8 * (n))))
548 #define ups(x, n) ((uint32_t)(x) << (8 * (n)))
549 #define bval(x, n) to_byte((x) >> (8 * (n)))
550 #define bytes2word(b0, b1, b2, b3) \
551 (((uint32_t)(b3) << 24) | ((uint32_t)(b2) << 16) | \
552 ((uint32_t)(b1) << 8) | (b0))
|
37 * This version is designed for flexibility and speed using operations on
38 * 32-bit words rather than operations on bytes. It can be compiled with
39 * either big or little endian internal byte order but is faster when the
40 * native byte order for the processor is used.
41 *
42 * THE CIPHER INTERFACE
43 *
44 * The cipher interface is implemented as an array of bytes in which lower
45 * AES bit sequence indexes map to higher numeric significance within bytes.
46 */
47
48 /*
49 * OpenSolaris changes
50 * 1. Added __cplusplus and _AESTAB_H header guards
51 * 2. Added header files sys/types.h and aes_impl.h
52 * 3. Added defines for AES_ENCRYPT, AES_DECRYPT, AES_REV_DKS, and ASM_AMD64_C
53 * 4. Moved defines for IS_BIG_ENDIAN, IS_LITTLE_ENDIAN, PLATFORM_BYTE_ORDER
54 * from brg_endian.h
55 * 5. Undefined VIA_ACE_POSSIBLE and ASSUME_VIA_ACE_PRESENT
56 * 6. Changed uint_8t and uint_32t to uint8_t and uint32_t
57 * 7. Defined aes_sw32 as htonl() for byte swapping
58 * 8. Cstyled and hdrchk code
59 *
60 */
61
62 #ifndef _AESOPT_H
63 #define _AESOPT_H
64
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68
69 #include <sys/types.h>
70 #include <sys/byteorder.h>
71 #include <aes_impl.h>
72
73 /* SUPPORT FEATURES */
74 #define AES_ENCRYPT /* if support for encryption is needed */
75 #define AES_DECRYPT /* if support for decryption is needed */
76
77 /* PLATFORM-SPECIFIC FEATURES */
78 #define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */
79 #define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */
80 #define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
81 #define AES_REV_DKS /* define to reverse decryption key schedule */
82
83
84 /*
85 * CONFIGURATION - THE USE OF DEFINES
86 * Later in this section there are a number of defines that control the
87 * operation of the code. In each section, the purpose of each define is
88 * explained so that the relevant form can be included or excluded by
89 * setting either 1's or 0's respectively on the branches of the related
90 * #if clauses. The following local defines should not be changed.
504 #endif
505
506 #if ENC_ROUND == NO_TABLES && ENC_UNROLL != NONE
507 #undef ENC_UNROLL
508 #define ENC_UNROLL NONE
509 #endif
510
511 #if DEC_ROUND == NO_TABLES && LAST_DEC_ROUND != NO_TABLES
512 #undef LAST_DEC_ROUND
513 #define LAST_DEC_ROUND NO_TABLES
514 #elif DEC_ROUND == ONE_TABLE && LAST_DEC_ROUND == FOUR_TABLES
515 #undef LAST_DEC_ROUND
516 #define LAST_DEC_ROUND ONE_TABLE
517 #endif
518
519 #if DEC_ROUND == NO_TABLES && DEC_UNROLL != NONE
520 #undef DEC_UNROLL
521 #define DEC_UNROLL NONE
522 #endif
523
524 #if (ALGORITHM_BYTE_ORDER == IS_LITTLE_ENDIAN)
525 #define aes_sw32 htonl
526 #elif defined(bswap32)
527 #define aes_sw32 bswap32
528 #elif defined(bswap_32)
529 #define aes_sw32 bswap_32
530 #else
531 #define brot(x, n) (((uint32_t)(x) << (n)) | ((uint32_t)(x) >> (32 - (n))))
532 #define aes_sw32(x) ((brot((x), 8) & 0x00ff00ff) | (brot((x), 24) & 0xff00ff00))
533 #endif
534
535
536 /*
537 * upr(x, n): rotates bytes within words by n positions, moving bytes to
538 * higher index positions with wrap around into low positions
539 * ups(x, n): moves bytes by n positions to higher index positions in
540 * words but without wrap around
541 * bval(x, n): extracts a byte from a word
542 *
543 * WARNING: The definitions given here are intended only for use with
544 * unsigned variables and with shift counts that are compile
545 * time constants
546 */
547
548 #if (ALGORITHM_BYTE_ORDER == IS_LITTLE_ENDIAN)
549 #define upr(x, n) (((uint32_t)(x) << (8 * (n))) | \
550 ((uint32_t)(x) >> (32 - 8 * (n))))
551 #define ups(x, n) ((uint32_t)(x) << (8 * (n)))
552 #define bval(x, n) to_byte((x) >> (8 * (n)))
553 #define bytes2word(b0, b1, b2, b3) \
554 (((uint32_t)(b3) << 24) | ((uint32_t)(b2) << 16) | \
555 ((uint32_t)(b1) << 8) | (b0))
|