|
33 | 33 | * |
34 | 34 | * $From: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $ |
35 | 35 | * |
36 | | - * $PostgreSQL: pgsql/contrib/pgcrypto/sha2.c,v 1.8 2006/10/04 00:29:46 momjian Exp $ |
| 36 | + * $PostgreSQL: pgsql/contrib/pgcrypto/sha2.c,v 1.9 2007/04/06 05:36:50 tgl Exp $ |
37 | 37 | */ |
38 | 38 |
|
39 | 39 | #include "postgres.h" |
|
56 | 56 | * |
57 | 57 | */ |
58 | 58 |
|
59 | | - |
60 | | -/*** SHA-256/384/512 Machine Architecture Definitions *****************/ |
61 | | -/* |
62 | | - * BYTE_ORDER NOTE: |
63 | | - * |
64 | | - * Please make sure that your system defines BYTE_ORDER. If your |
65 | | - * architecture is little-endian, make sure it also defines |
66 | | - * LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are |
67 | | - * equivilent. |
68 | | - * |
69 | | - * If your system does not define the above, then you can do so by |
70 | | - * hand like this: |
71 | | - * |
72 | | - * #define LITTLE_ENDIAN 1234 |
73 | | - * #define BIG_ENDIAN 4321 |
74 | | - * |
75 | | - * And for little-endian machines, add: |
76 | | - * |
77 | | - * #define BYTE_ORDER LITTLE_ENDIAN |
78 | | - * |
79 | | - * Or for big-endian machines: |
80 | | - * |
81 | | - * #define BYTE_ORDER BIG_ENDIAN |
82 | | - * |
83 | | - * The FreeBSD machine this was written on defines BYTE_ORDER |
84 | | - * appropriately by including <sys/types.h> (which in turn includes |
85 | | - * <machine/endian.h> where the appropriate definitions are actually |
86 | | - * made). |
87 | | - */ |
88 | | -#if !defined(BYTE_ORDER) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN) |
89 | | -#error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN |
90 | | -#endif |
91 | | - |
92 | | - |
93 | 59 | /*** SHA-256/384/512 Various Length Definitions ***********************/ |
94 | 60 | /* NOTE: Most of these are in sha2.h */ |
95 | 61 | #define SHA256_SHORT_BLOCK_LENGTH (SHA256_BLOCK_LENGTH - 8) |
|
98 | 64 |
|
99 | 65 |
|
100 | 66 | /*** ENDIAN REVERSAL MACROS *******************************************/ |
101 | | -#if BYTE_ORDER == LITTLE_ENDIAN |
| 67 | +#ifndef WORDS_BIGENDIAN |
102 | 68 | #define REVERSE32(w,x) { \ |
103 | 69 | uint32 tmp = (w); \ |
104 | 70 | tmp = (tmp >> 16) | (tmp << 16); \ |
|
112 | 78 | (x) = ((tmp & 0xffff0000ffff0000ULL) >> 16) | \ |
113 | 79 | ((tmp & 0x0000ffff0000ffffULL) << 16); \ |
114 | 80 | } |
115 | | -#endif /* BYTE_ORDER == LITTLE_ENDIAN */ |
| 81 | +#endif /* not bigendian */ |
116 | 82 |
|
117 | 83 | /* |
118 | 84 | * Macro for incrementally adding the unsigned 64-bit integer n to the |
@@ -539,7 +505,7 @@ SHA256_Last(SHA256_CTX * context) |
539 | 505 | unsigned int usedspace; |
540 | 506 |
|
541 | 507 | usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH; |
542 | | -#if BYTE_ORDER == LITTLE_ENDIAN |
| 508 | +#ifndef WORDS_BIGENDIAN |
543 | 509 | /* Convert FROM host byte order */ |
544 | 510 | REVERSE64(context->bitcount, context->bitcount); |
545 | 511 | #endif |
@@ -589,7 +555,7 @@ SHA256_Final(uint8 digest[], SHA256_CTX * context) |
589 | 555 | { |
590 | 556 | SHA256_Last(context); |
591 | 557 |
|
592 | | -#if BYTE_ORDER == LITTLE_ENDIAN |
| 558 | +#ifndef WORDS_BIGENDIAN |
593 | 559 | { |
594 | 560 | /* Convert TO host byte order */ |
595 | 561 | int j; |
@@ -865,7 +831,7 @@ SHA512_Last(SHA512_CTX * context) |
865 | 831 | unsigned int usedspace; |
866 | 832 |
|
867 | 833 | usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH; |
868 | | -#if BYTE_ORDER == LITTLE_ENDIAN |
| 834 | +#ifndef WORDS_BIGENDIAN |
869 | 835 | /* Convert FROM host byte order */ |
870 | 836 | REVERSE64(context->bitcount[0], context->bitcount[0]); |
871 | 837 | REVERSE64(context->bitcount[1], context->bitcount[1]); |
@@ -918,7 +884,7 @@ SHA512_Final(uint8 digest[], SHA512_CTX * context) |
918 | 884 | SHA512_Last(context); |
919 | 885 |
|
920 | 886 | /* Save the hash data for output: */ |
921 | | -#if BYTE_ORDER == LITTLE_ENDIAN |
| 887 | +#ifndef WORDS_BIGENDIAN |
922 | 888 | { |
923 | 889 | /* Convert TO host byte order */ |
924 | 890 | int j; |
@@ -963,7 +929,7 @@ SHA384_Final(uint8 digest[], SHA384_CTX * context) |
963 | 929 | SHA512_Last((SHA512_CTX *) context); |
964 | 930 |
|
965 | 931 | /* Save the hash data for output: */ |
966 | | -#if BYTE_ORDER == LITTLE_ENDIAN |
| 932 | +#ifndef WORDS_BIGENDIAN |
967 | 933 | { |
968 | 934 | /* Convert TO host byte order */ |
969 | 935 | int j; |
@@ -1006,7 +972,7 @@ SHA224_Final(uint8 digest[], SHA224_CTX * context) |
1006 | 972 | { |
1007 | 973 | SHA256_Last(context); |
1008 | 974 |
|
1009 | | -#if BYTE_ORDER == LITTLE_ENDIAN |
| 975 | +#ifndef WORDS_BIGENDIAN |
1010 | 976 | { |
1011 | 977 | /* Convert TO host byte order */ |
1012 | 978 | int j; |
|
0 commit comments