Revision 1.7 by

Revision 1.8 by

… | … | ||
---|---|---|---|

53 | #define a_const __attribute__((__const__)) | 53 | #define a_const __attribute__((__const__)) |

54 | 54 | ||

55 | /* Useful defines & typedefs */ | 55 | /* Useful defines & typedefs */ |

56 | 56 | ||

57 | #if defined(U64TYPE) && (defined(USE_64_BIT_INT) || ((BYTEORDER != 0x1234) && (BYTEORDER != 0x4321))) | 57 | #if defined(U64TYPE) && (defined(USE_64_BIT_INT) || ((BYTEORDER != 0x1234) && (BYTEORDER != 0x4321))) |

58 | typedef U64TYPE ULONG; | 58 | typedef U64TYPE XULONG; |

59 | # if BYTEORDER == 0x1234 | 59 | # if BYTEORDER == 0x1234 |

60 | # undef BYTEORDER | 60 | # undef BYTEORDER |

61 | # define BYTEORDER 0x12345678 | 61 | # define BYTEORDER 0x12345678 |

62 | # elif BYTEORDER == 0x4321 | 62 | # elif BYTEORDER == 0x4321 |

63 | # undef BYTEORDER | 63 | # undef BYTEORDER |

64 | # define BYTEORDER 0x87654321 | 64 | # define BYTEORDER 0x87654321 |

65 | # endif | 65 | # endif |

66 | #else | 66 | #else |

67 | typedef uint_fast32_t ULONG; /* 32-or-more-bit quantity */ | 67 | typedef uint_fast32_t XULONG; /* 32-or-more-bit quantity */ |

68 | #endif | 68 | #endif |

69 | 69 | ||

70 | #if GCCX86ASM | 70 | #if GCCX86ASM |

71 | # define zprefix(n) ({ int _r; __asm__ ("bsrl %1, %0" : "=r" (_r) : "r" (n)); 31 - _r ; }) | 71 | # define zprefix(n) ({ int _r; __asm__ ("bsrl %1, %0" : "=r" (_r) : "r" (n)); 31 - _r ; }) |

72 | #elif __GNUC__ > 2 && __GNUC_MINOR__ > 3 | 72 | #elif __GNUC__ > 2 && __GNUC_MINOR__ > 3 |

73 | # define zprefix(n) (__extension__ ({ uint32_t n__ = (n); n ? __builtin_clz (n) : 32; })) | 73 | # define zprefix(n) (__extension__ ({ uint32_t n__ = (n); n ? __builtin_clz (n) : 32; })) |

74 | #else | 74 | #else |

75 | static int a_const zprefix (ULONG n) | 75 | static int a_const zprefix (U32 n) |

76 | { | 76 | { |

77 | static char zp[256] = | 77 | static char zp[256] = |

78 | { | 78 | { |

79 | 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, | 79 | 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, |

80 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | 80 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |

… | … | ||

104 | 104 | ||

105 | #define SHA_BLOCKSIZE 64 | 105 | #define SHA_BLOCKSIZE 64 |

106 | #define SHA_DIGESTSIZE 20 | 106 | #define SHA_DIGESTSIZE 20 |

107 | 107 | ||

108 | typedef struct { | 108 | typedef struct { |

109 | ULONG digest[5]; /* message digest */ | 109 | U32 digest[5]; /* message digest */ |

110 | ULONG count; /* 32-bit bit count */ | 110 | U32 count; /* 32-bit bit count */ |

111 | int local; /* unprocessed amount in data */ | 111 | int local; /* unprocessed amount in data */ |

112 | U8 data[SHA_BLOCKSIZE]; /* SHA data buffer */ | 112 | U8 data[SHA_BLOCKSIZE]; /* SHA data buffer */ |

113 | } SHA_INFO; | 113 | } SHA_INFO; |

114 | 114 | ||

115 | 115 | ||

… | … | ||

152 | 152 | ||

153 | static void a_regparm(1) sha_transform(SHA_INFO *restrict sha_info) | 153 | static void a_regparm(1) sha_transform(SHA_INFO *restrict sha_info) |

154 | { | 154 | { |

155 | int i; | 155 | int i; |

156 | U8 *restrict dp; | 156 | U8 *restrict dp; |

157 | ULONG T, A, B, C, D, E, W[80], *restrict WP; | 157 | U32 A, B, C, D, E, W[80], *restrict WP; |

158 | XULONG T; | ||

158 | 159 | ||

159 | dp = sha_info->data; | 160 | dp = sha_info->data; |

160 | 161 | ||

161 | #if BYTEORDER == 0x1234 | 162 | #if BYTEORDER == 0x1234 |

162 | assert(sizeof(ULONG) == 4); | 163 | assert(sizeof(XULONG) == 4); |

163 | # ifdef HAS_NTOHL | 164 | # ifdef HAS_NTOHL |

164 | for (i = 0; i < 16; ++i) { | 165 | for (i = 0; i < 16; ++i) { |

165 | T = *((ULONG *) dp); | 166 | T = *((XULONG *) dp); |

166 | dp += 4; | 167 | dp += 4; |

167 | W[i] = ntohl (T); | 168 | W[i] = ntohl (T); |

168 | } | 169 | } |

169 | # else | 170 | # else |

170 | for (i = 0; i < 16; ++i) { | 171 | for (i = 0; i < 16; ++i) { |

171 | T = *((ULONG *) dp); | 172 | T = *((XULONG *) dp); |

172 | dp += 4; | 173 | dp += 4; |

173 | W[i] = ((T << 24) & 0xff000000) | ((T << 8) & 0x00ff0000) | | 174 | W[i] = ((T << 24) & 0xff000000) | ((T << 8) & 0x00ff0000) | |

174 | ((T >> 8) & 0x0000ff00) | ((T >> 24) & 0x000000ff); | 175 | ((T >> 8) & 0x0000ff00) | ((T >> 24) & 0x000000ff); |

175 | } | 176 | } |

176 | # endif | 177 | # endif |

177 | #elif BYTEORDER == 0x4321 | 178 | #elif BYTEORDER == 0x4321 |

178 | assert(sizeof(ULONG) == 4); | 179 | assert(sizeof(XULONG) == 4); |

179 | for (i = 0; i < 16; ++i) { | 180 | for (i = 0; i < 16; ++i) { |

180 | T = *((ULONG *) dp); | 181 | T = *((XULONG *) dp); |

181 | dp += 4; | 182 | dp += 4; |

182 | W[i] = T32(T); | 183 | W[i] = T32(T); |

183 | } | 184 | } |

184 | #elif BYTEORDER == 0x12345678 | 185 | #elif BYTEORDER == 0x12345678 |

185 | assert(sizeof(ULONG) == 8); | 186 | assert(sizeof(XULONG) == 8); |

186 | for (i = 0; i < 16; i += 2) { | 187 | for (i = 0; i < 16; i += 2) { |

187 | T = *((ULONG *) dp); | 188 | T = *((XULONG *) dp); |

188 | dp += 8; | 189 | dp += 8; |

189 | W[i] = ((T << 24) & 0xff000000) | ((T << 8) & 0x00ff0000) | | 190 | W[i] = ((T << 24) & 0xff000000) | ((T << 8) & 0x00ff0000) | |

190 | ((T >> 8) & 0x0000ff00) | ((T >> 24) & 0x000000ff); | 191 | ((T >> 8) & 0x0000ff00) | ((T >> 24) & 0x000000ff); |

191 | T >>= 32; | 192 | T >>= 32; |

192 | W[i+1] = ((T << 24) & 0xff000000) | ((T << 8) & 0x00ff0000) | | 193 | W[i+1] = ((T << 24) & 0xff000000) | ((T << 8) & 0x00ff0000) | |

193 | ((T >> 8) & 0x0000ff00) | ((T >> 24) & 0x000000ff); | 194 | ((T >> 8) & 0x0000ff00) | ((T >> 24) & 0x000000ff); |

194 | } | 195 | } |

195 | #elif BYTEORDER == 0x87654321 | 196 | #elif BYTEORDER == 0x87654321 |

196 | assert(sizeof(ULONG) == 8); | 197 | assert(sizeof(XULONG) == 8); |

197 | for (i = 0; i < 16; i += 2) { | 198 | for (i = 0; i < 16; i += 2) { |

198 | T = *((ULONG *) dp); | 199 | T = *((XULONG *) dp); |

199 | dp += 8; | 200 | dp += 8; |

200 | W[i] = T32(T >> 32); | 201 | W[i] = T32(T >> 32); |

201 | W[i+1] = T32(T); | 202 | W[i+1] = T32(T); |

202 | } | 203 | } |

203 | #else | 204 | #else |

– |
Removed lines |

+ |
Added lines |

< |
Changed lines |

> |
Changed lines |