md32_common.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /* crypto/md32_common.h */
  2. /*
  3. * This is a generic 32 bit "collector" for message digest algorithms.
  4. * Whenever needed it collects input character stream into chunks of
  5. * 32 bit values and invokes a block function that performs actual hash
  6. * calculations.
  7. *
  8. * Porting guide.
  9. *
  10. * Obligatory macros:
  11. *
  12. * DATA_ORDER_IS_BIG_ENDIAN or DATA_ORDER_IS_LITTLE_ENDIAN
  13. * this macro defines byte order of input stream.
  14. * HASH_CBLOCK
  15. * size of a unit chunk HASH_BLOCK operates on.
  16. * HASH_LONG
  17. * has to be at lest 32 bit wide, if it's wider, then
  18. * HASH_LONG_LOG2 *has to* be defined along
  19. * HASH_CTX
  20. * context structure that at least contains following
  21. * members:
  22. * typedef struct {
  23. * ...
  24. * HASH_LONG Nl,Nh;
  25. * HASH_LONG data[HASH_LBLOCK];
  26. * int num;
  27. * ...
  28. * } HASH_CTX;
  29. * HASH_UPDATE
  30. * name of "Update" function, implemented here.
  31. * HASH_TRANSFORM
  32. * name of "Transform" function, implemented here.
  33. * HASH_FINAL
  34. * name of "Final" function, implemented here.
  35. * HASH_BLOCK_HOST_ORDER
  36. * name of "block" function treating *aligned* input message
  37. * in host byte order, implemented externally.
  38. * HASH_BLOCK_DATA_ORDER
  39. * name of "block" function treating *unaligned* input message
  40. * in original (data) byte order, implemented externally (it
  41. * actually is optional if data and host are of the same
  42. * "endianess").
  43. * HASH_MAKE_STRING
  44. * macro convering context variables to an ASCII hash string.
  45. *
  46. * Optional macros:
  47. *
  48. * B_ENDIAN or L_ENDIAN
  49. * defines host byte-order.
  50. * HASH_LONG_LOG2
  51. * defaults to 2 if not states otherwise.
  52. * HASH_LBLOCK
  53. * assumed to be HASH_CBLOCK/4 if not stated otherwise.
  54. * HASH_BLOCK_DATA_ORDER_ALIGNED
  55. * alternative "block" function capable of treating
  56. * aligned input message in original (data) order,
  57. * implemented externally.
  58. *
  59. * MD5 example:
  60. *
  61. * #define DATA_ORDER_IS_LITTLE_ENDIAN
  62. *
  63. * #define HASH_LONG MD5_LONG
  64. * #define HASH_LONG_LOG2 MD5_LONG_LOG2
  65. * #define HASH_CTX MD5_CTX
  66. * #define HASH_CBLOCK MD5_CBLOCK
  67. * #define HASH_LBLOCK MD5_LBLOCK
  68. * #define HASH_UPDATE MD5_Update
  69. * #define HASH_TRANSFORM MD5_Transform
  70. * #define HASH_FINAL MD5_Final
  71. * #define HASH_BLOCK_HOST_ORDER md5_block_host_order
  72. * #define HASH_BLOCK_DATA_ORDER md5_block_data_order
  73. *
  74. * <appro@fy.chalmers.se>
  75. */
  76. #ifdef HAVE_CONFIG_H
  77. #include "config.h"
  78. #endif /* HAVE_CONFIG_H */
  79. #include "src/compat/compat.h"
  80. #if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN)
  81. #error "DATA_ORDER must be defined!"
  82. #endif
  83. #ifndef HASH_CBLOCK
  84. #error "HASH_CBLOCK must be defined!"
  85. #endif
  86. #ifndef HASH_LONG
  87. #error "HASH_LONG must be defined!"
  88. #endif
  89. #ifndef HASH_CTX
  90. #error "HASH_CTX must be defined!"
  91. #endif
  92. #ifndef HASH_UPDATE
  93. #error "HASH_UPDATE must be defined!"
  94. #endif
  95. #ifndef HASH_TRANSFORM
  96. #error "HASH_TRANSFORM must be defined!"
  97. #endif
  98. #ifndef HASH_FINAL
  99. #error "HASH_FINAL must be defined!"
  100. #endif
  101. #ifndef HASH_BLOCK_HOST_ORDER
  102. #error "HASH_BLOCK_HOST_ORDER must be defined!"
  103. #endif
  104. #if 0
  105. /*
  106. * Moved below as it's required only if HASH_BLOCK_DATA_ORDER_ALIGNED
  107. * isn't defined.
  108. */
  109. #ifndef HASH_BLOCK_DATA_ORDER
  110. #error "HASH_BLOCK_DATA_ORDER must be defined!"
  111. #endif
  112. #endif
  113. #ifndef HASH_LBLOCK
  114. #define HASH_LBLOCK (HASH_CBLOCK/4)
  115. #endif
  116. #ifndef HASH_LONG_LOG2
  117. #define HASH_LONG_LOG2 2
  118. #endif
  119. /*
  120. * Engage compiler specific rotate intrinsic function if available.
  121. */
  122. #undef ROTATE
  123. #ifndef PEDANTIC
  124. # if 0 /* defined(_MSC_VER) */
  125. # define ROTATE(a,n) _lrotl(a,n)
  126. # elif defined(__MWERKS__)
  127. # if defined(__POWERPC__)
  128. # define ROTATE(a,n) __rlwinm(a,n,0,31)
  129. # elif defined(__MC68K__)
  130. /* Motorola specific tweak. <appro@fy.chalmers.se> */
  131. # define ROTATE(a,n) ( n<24 ? __rol(a,n) : __ror(a,32-n) )
  132. # else
  133. # define ROTATE(a,n) __rol(a,n)
  134. # endif
  135. # elif defined(__GNUC__) && __GNUC__>=2
  136. /*
  137. * Some GNU C inline assembler templates. Note that these are
  138. * rotates by *constant* number of bits! But that's exactly
  139. * what we need here...
  140. *
  141. * <appro@fy.chalmers.se>
  142. */
  143. # if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
  144. # define ROTATE(a,n) ({ register unsigned int ret; \
  145. asm ( \
  146. "roll %1,%0" \
  147. : "=r"(ret) \
  148. : "I"(n), "0"(a) \
  149. : "cc"); \
  150. ret; \
  151. })
  152. # elif defined(__powerpc) || defined(__ppc)
  153. # define ROTATE(a,n) ({ register unsigned int ret; \
  154. asm ( \
  155. "rlwinm %0,%1,%2,0,31" \
  156. : "=r"(ret) \
  157. : "r"(a), "I"(n)); \
  158. ret; \
  159. })
  160. # endif
  161. # endif
  162. /*
  163. * Engage compiler specific "fetch in reverse byte order"
  164. * intrinsic function if available.
  165. */
  166. # if defined(__GNUC__) && __GNUC__>=2
  167. /* some GNU C inline assembler templates by <appro@fy.chalmers.se> */
  168. # if (defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)) && !defined(I386_ONLY)
  169. # define BE_FETCH32(a) ({ register unsigned int l=(a);\
  170. asm ( \
  171. "bswapl %0" \
  172. : "=r"(l) : "0"(l)); \
  173. l; \
  174. })
  175. # elif defined(__powerpc)
  176. # define LE_FETCH32(a) ({ register unsigned int l; \
  177. asm ( \
  178. "lwbrx %0,0,%1" \
  179. : "=r"(l) \
  180. : "r"(a)); \
  181. l; \
  182. })
  183. # elif defined(__sparc)
  184. # define LE_FETCH32(a) ({ register unsigned int l; \
  185. asm ( \
  186. "lda [%1]#ASI_PRIMARY_LITTLE,%0"\
  187. : "=r"(l) \
  188. : "r"(a)); \
  189. l; \
  190. })
  191. # endif
  192. # endif
  193. #endif /* PEDANTIC */
  194. #if HASH_LONG_LOG2==2 /* Engage only if sizeof(HASH_LONG)== 4 */
  195. /* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
  196. #ifdef ROTATE
  197. /* 5 instructions with rotate instruction, else 9 */
  198. #define REVERSE_FETCH32(a,l) ( \
  199. l=*(const HASH_LONG *)(a), \
  200. ((ROTATE(l,8)&0x00FF00FF)|(ROTATE((l&0x00FF00FF),24))) \
  201. )
  202. #else
  203. /* 6 instructions with rotate instruction, else 8 */
  204. #define REVERSE_FETCH32(a,l) ( \
  205. l=*(const HASH_LONG *)(a), \
  206. l=(((l>>8)&0x00FF00FF)|((l&0x00FF00FF)<<8)), \
  207. ROTATE(l,16) \
  208. )
  209. /*
  210. * Originally the middle line started with l=(((l&0xFF00FF00)>>8)|...
  211. * It's rewritten as above for two reasons:
  212. * - RISCs aren't good at long constants and have to explicitely
  213. * compose 'em with several (well, usually 2) instructions in a
  214. * register before performing the actual operation and (as you
  215. * already realized:-) having same constant should inspire the
  216. * compiler to permanently allocate the only register for it;
  217. * - most modern CPUs have two ALUs, but usually only one has
  218. * circuitry for shifts:-( this minor tweak inspires compiler
  219. * to schedule shift instructions in a better way...
  220. *
  221. * <appro@fy.chalmers.se>
  222. */
  223. #endif
  224. #endif
  225. #ifndef ROTATE
  226. #define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
  227. #endif
  228. /*
  229. * Make some obvious choices. E.g., HASH_BLOCK_DATA_ORDER_ALIGNED
  230. * and HASH_BLOCK_HOST_ORDER ought to be the same if input data
  231. * and host are of the same "endianess". It's possible to mask
  232. * this with blank #define HASH_BLOCK_DATA_ORDER though...
  233. *
  234. * <appro@fy.chalmers.se>
  235. */
  236. #if defined(B_ENDIAN)
  237. # if defined(DATA_ORDER_IS_BIG_ENDIAN)
  238. # if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
  239. # define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
  240. # endif
  241. # elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
  242. # ifndef HOST_FETCH32
  243. # ifdef LE_FETCH32
  244. # define HOST_FETCH32(p,l) LE_FETCH32(p)
  245. # elif defined(REVERSE_FETCH32)
  246. # define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
  247. # endif
  248. # endif
  249. # endif
  250. #elif defined(L_ENDIAN)
  251. # if defined(DATA_ORDER_IS_LITTLE_ENDIAN)
  252. # if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
  253. # define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
  254. # endif
  255. # elif defined(DATA_ORDER_IS_BIG_ENDIAN)
  256. # ifndef HOST_FETCH32
  257. # ifdef BE_FETCH32
  258. # define HOST_FETCH32(p,l) BE_FETCH32(p)
  259. # elif defined(REVERSE_FETCH32)
  260. # define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
  261. # endif
  262. # endif
  263. # endif
  264. #endif
  265. #if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
  266. #ifndef HASH_BLOCK_DATA_ORDER
  267. #error "HASH_BLOCK_DATA_ORDER must be defined!"
  268. #endif
  269. #endif
  270. #if defined(DATA_ORDER_IS_BIG_ENDIAN)
  271. #define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
  272. l|=(((unsigned long)(*((c)++)))<<16), \
  273. l|=(((unsigned long)(*((c)++)))<< 8), \
  274. l|=(((unsigned long)(*((c)++))) ), \
  275. l)
  276. #define HOST_p_c2l(c,l,n) { \
  277. switch (n) { \
  278. case 0: l =((unsigned long)(*((c)++)))<<24; \
  279. case 1: l|=((unsigned long)(*((c)++)))<<16; \
  280. case 2: l|=((unsigned long)(*((c)++)))<< 8; \
  281. case 3: l|=((unsigned long)(*((c)++))); \
  282. } }
  283. #define HOST_p_c2l_p(c,l,sc,len) { \
  284. switch (sc) { \
  285. case 0: l =((unsigned long)(*((c)++)))<<24; \
  286. if (--len == 0) break; \
  287. case 1: l|=((unsigned long)(*((c)++)))<<16; \
  288. if (--len == 0) break; \
  289. case 2: l|=((unsigned long)(*((c)++)))<< 8; \
  290. } }
  291. /* NOTE the pointer is not incremented at the end of this */
  292. #define HOST_c2l_p(c,l,n) { \
  293. l=0; (c)+=n; \
  294. switch (n) { \
  295. case 3: l =((unsigned long)(*(--(c))))<< 8; \
  296. case 2: l|=((unsigned long)(*(--(c))))<<16; \
  297. case 1: l|=((unsigned long)(*(--(c))))<<24; \
  298. } }
  299. #define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
  300. *((c)++)=(unsigned char)(((l)>>16)&0xff), \
  301. *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
  302. *((c)++)=(unsigned char)(((l) )&0xff), \
  303. l)
  304. #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
  305. #define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
  306. l|=(((unsigned long)(*((c)++)))<< 8), \
  307. l|=(((unsigned long)(*((c)++)))<<16), \
  308. l|=(((unsigned long)(*((c)++)))<<24), \
  309. l)
  310. #define HOST_p_c2l(c,l,n) { \
  311. switch (n) { \
  312. case 0: l =((unsigned long)(*((c)++))); \
  313. case 1: l|=((unsigned long)(*((c)++)))<< 8; \
  314. case 2: l|=((unsigned long)(*((c)++)))<<16; \
  315. case 3: l|=((unsigned long)(*((c)++)))<<24; \
  316. } }
  317. #define HOST_p_c2l_p(c,l,sc,len) { \
  318. switch (sc) { \
  319. case 0: l =((unsigned long)(*((c)++))); \
  320. if (--len == 0) break; \
  321. case 1: l|=((unsigned long)(*((c)++)))<< 8; \
  322. if (--len == 0) break; \
  323. case 2: l|=((unsigned long)(*((c)++)))<<16; \
  324. } }
  325. /* NOTE the pointer is not incremented at the end of this */
  326. #define HOST_c2l_p(c,l,n) { \
  327. l=0; (c)+=n; \
  328. switch (n) { \
  329. case 3: l =((unsigned long)(*(--(c))))<<16; \
  330. case 2: l|=((unsigned long)(*(--(c))))<< 8; \
  331. case 1: l|=((unsigned long)(*(--(c)))); \
  332. } }
  333. #define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
  334. *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
  335. *((c)++)=(unsigned char)(((l)>>16)&0xff), \
  336. *((c)++)=(unsigned char)(((l)>>24)&0xff), \
  337. l)
  338. #endif
  339. /*
  340. * Time for some action:-)
  341. */
  342. int HASH_UPDATE (HASH_CTX *c, const void *data_, unsigned long len)
  343. {
  344. const unsigned char *data = (const unsigned char *) data_;
  345. register HASH_LONG * p;
  346. register unsigned long l;
  347. int sw,sc,ew,ec;
  348. if (len==0) return 1;
  349. l=(c->Nl+(len<<3))&0xffffffffL;
  350. /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
  351. * Wei Dai <weidai@eskimo.com> for pointing it out. */
  352. if (l < c->Nl) /* overflow */
  353. c->Nh++;
  354. c->Nh+=(len>>29);
  355. c->Nl=l;
  356. if (c->num != 0)
  357. {
  358. p=c->data;
  359. sw=c->num>>2;
  360. sc=c->num&0x03;
  361. if ((c->num+len) >= HASH_CBLOCK)
  362. {
  363. l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
  364. for (; sw<HASH_LBLOCK; sw++)
  365. {
  366. HOST_c2l(data,l); p[sw]=l;
  367. }
  368. HASH_BLOCK_HOST_ORDER (c,p,1);
  369. len-=(HASH_CBLOCK-c->num);
  370. c->num=0;
  371. /* drop through and do the rest */
  372. }
  373. else
  374. {
  375. c->num+=len;
  376. if ((sc+len) < 4) /* ugly, add char's to a word */
  377. {
  378. l=p[sw]; HOST_p_c2l_p(data,l,sc,len); p[sw]=l;
  379. }
  380. else
  381. {
  382. ew=(c->num>>2);
  383. ec=(c->num&0x03);
  384. if (sc)
  385. l=p[sw];
  386. HOST_p_c2l(data,l,sc);
  387. p[sw++]=l;
  388. for (; sw < ew; sw++)
  389. {
  390. HOST_c2l(data,l); p[sw]=l;
  391. }
  392. if (ec)
  393. {
  394. HOST_c2l_p(data,l,ec); p[sw]=l;
  395. }
  396. }
  397. return 1;
  398. }
  399. }
  400. sw=len/HASH_CBLOCK;
  401. if (sw > 0)
  402. {
  403. #if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
  404. /*
  405. * Note that HASH_BLOCK_DATA_ORDER_ALIGNED gets defined
  406. * only if sizeof(HASH_LONG)==4.
  407. */
  408. if ((((unsigned long)data)%4) == 0)
  409. {
  410. /* data is properly aligned so that we can cast it: */
  411. HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,sw);
  412. sw*=HASH_CBLOCK;
  413. data+=sw;
  414. len-=sw;
  415. }
  416. else
  417. #if !defined(HASH_BLOCK_DATA_ORDER)
  418. while (sw--)
  419. {
  420. egg_memcpy (p=c->data,data,HASH_CBLOCK);
  421. HASH_BLOCK_DATA_ORDER_ALIGNED(c,p,1);
  422. data+=HASH_CBLOCK;
  423. len-=HASH_CBLOCK;
  424. }
  425. #endif
  426. #endif
  427. #if defined(HASH_BLOCK_DATA_ORDER)
  428. {
  429. HASH_BLOCK_DATA_ORDER(c,data,sw);
  430. sw*=HASH_CBLOCK;
  431. data+=sw;
  432. len-=sw;
  433. }
  434. #endif
  435. }
  436. if (len!=0)
  437. {
  438. p = c->data;
  439. c->num = len;
  440. ew=len>>2; /* words to copy */
  441. ec=len&0x03;
  442. for (; ew; ew--,p++)
  443. {
  444. HOST_c2l(data,l); *p=l;
  445. }
  446. HOST_c2l_p(data,l,ec);
  447. *p=l;
  448. }
  449. return 1;
  450. }
  451. void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data)
  452. {
  453. #if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
  454. if ((((unsigned long)data)%4) == 0)
  455. /* data is properly aligned so that we can cast it: */
  456. HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,1);
  457. else
  458. #if !defined(HASH_BLOCK_DATA_ORDER)
  459. {
  460. egg_memcpy (c->data,data,HASH_CBLOCK);
  461. HASH_BLOCK_DATA_ORDER_ALIGNED (c,c->data,1);
  462. }
  463. #endif
  464. #endif
  465. #if defined(HASH_BLOCK_DATA_ORDER)
  466. HASH_BLOCK_DATA_ORDER (c,data,1);
  467. #endif
  468. }
  469. int HASH_FINAL (unsigned char *md, HASH_CTX *c)
  470. {
  471. register HASH_LONG *p;
  472. register unsigned long l;
  473. register int i,j;
  474. static const unsigned char end[4]={0x80,0x00,0x00,0x00};
  475. const unsigned char *cp=end;
  476. /* c->num should definitly have room for at least one more byte. */
  477. p=c->data;
  478. i=c->num>>2;
  479. j=c->num&0x03;
  480. #if 0
  481. /* purify often complains about the following line as an
  482. * Uninitialized Memory Read. While this can be true, the
  483. * following p_c2l macro will reset l when that case is true.
  484. * This is because j&0x03 contains the number of 'valid' bytes
  485. * already in p[i]. If and only if j&0x03 == 0, the UMR will
  486. * occur but this is also the only time p_c2l will do
  487. * l= *(cp++) instead of l|= *(cp++)
  488. * Many thanks to Alex Tang <altitude@cic.net> for pickup this
  489. * 'potential bug' */
  490. #ifdef PURIFY
  491. if (j==0) p[i]=0; /* Yeah, but that's not the way to fix it:-) */
  492. #endif
  493. l=p[i];
  494. #else
  495. l = (j==0) ? 0 : p[i];
  496. #endif
  497. HOST_p_c2l(cp,l,j); p[i++]=l; /* i is the next 'undefined word' */
  498. if (i>(HASH_LBLOCK-2)) /* save room for Nl and Nh */
  499. {
  500. if (i<HASH_LBLOCK) p[i]=0;
  501. HASH_BLOCK_HOST_ORDER (c,p,1);
  502. i=0;
  503. }
  504. for (; i<(HASH_LBLOCK-2); i++)
  505. p[i]=0;
  506. #if defined(DATA_ORDER_IS_BIG_ENDIAN)
  507. p[HASH_LBLOCK-2]=c->Nh;
  508. p[HASH_LBLOCK-1]=c->Nl;
  509. #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
  510. p[HASH_LBLOCK-2]=c->Nl;
  511. p[HASH_LBLOCK-1]=c->Nh;
  512. #endif
  513. HASH_BLOCK_HOST_ORDER (c,p,1);
  514. #ifndef HASH_MAKE_STRING
  515. #error "HASH_MAKE_STRING must be defined!"
  516. #else
  517. HASH_MAKE_STRING(c,md);
  518. #endif
  519. c->num=0;
  520. /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack
  521. * but I'm not worried :-)
  522. OPENSSL_cleanse((void *)c,sizeof(HASH_CTX));
  523. */
  524. return 1;
  525. }
  526. #ifndef MD32_REG_T
  527. #define MD32_REG_T long
  528. /*
  529. * This comment was originaly written for MD5, which is why it
  530. * discusses A-D. But it basically applies to all 32-bit digests,
  531. * which is why it was moved to common header file.
  532. *
  533. * In case you wonder why A-D are declared as long and not
  534. * as MD5_LONG. Doing so results in slight performance
  535. * boost on LP64 architectures. The catch is we don't
  536. * really care if 32 MSBs of a 64-bit register get polluted
  537. * with eventual overflows as we *save* only 32 LSBs in
  538. * *either* case. Now declaring 'em long excuses the compiler
  539. * from keeping 32 MSBs zeroed resulting in 13% performance
  540. * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
  541. * Well, to be honest it should say that this *prevents*
  542. * performance degradation.
  543. * <appro@fy.chalmers.se>
  544. * Apparently there're LP64 compilers that generate better
  545. * code if A-D are declared int. Most notably GCC-x86_64
  546. * generates better code.
  547. * <appro@fy.chalmers.se>
  548. */
  549. #endif