xref: /minix3/crypto/external/bsd/openssl/dist/bugs/sgiccbug.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1ebfedea0SLionel Sambuc /* NOCW */
2ebfedea0SLionel Sambuc /* sgibug.c */
3ebfedea0SLionel Sambuc /* bug found by Eric Young (eay@mincom.oz.au) May 95 */
4ebfedea0SLionel Sambuc 
5ebfedea0SLionel Sambuc #include <stdio.h>
6ebfedea0SLionel Sambuc 
7*0a6a1f1dSLionel Sambuc /*
8*0a6a1f1dSLionel Sambuc  * This compiler bug it present on IRIX 5.3, 5.1 and 4.0.5 (these are the
9*0a6a1f1dSLionel Sambuc  * only versions of IRIX I have access to. defining FIXBUG removes the bug.
10*0a6a1f1dSLionel Sambuc  * (bug is still present in IRIX 6.3 according to Gage
11*0a6a1f1dSLionel Sambuc  * <agage@forgetmenot.Mines.EDU>
12ebfedea0SLionel Sambuc  */
13ebfedea0SLionel Sambuc 
14*0a6a1f1dSLionel Sambuc /*-
15*0a6a1f1dSLionel Sambuc  * Compare the output from
16ebfedea0SLionel Sambuc  * cc sgiccbug.c; ./a.out
17ebfedea0SLionel Sambuc  * and
18ebfedea0SLionel Sambuc  * cc -O sgiccbug.c; ./a.out
19ebfedea0SLionel Sambuc  */
20ebfedea0SLionel Sambuc 
21*0a6a1f1dSLionel Sambuc static unsigned long a[4] =
22*0a6a1f1dSLionel Sambuc     { 0x01234567, 0x89ABCDEF, 0xFEDCBA98, 0x76543210 };
23*0a6a1f1dSLionel Sambuc static unsigned long b[4] =
24*0a6a1f1dSLionel Sambuc     { 0x89ABCDEF, 0xFEDCBA98, 0x76543210, 0x01234567 };
25*0a6a1f1dSLionel Sambuc static unsigned long c[4] =
26*0a6a1f1dSLionel Sambuc     { 0x77777778, 0x8ACF1357, 0x88888888, 0x7530ECA9 };
27ebfedea0SLionel Sambuc 
main()28ebfedea0SLionel Sambuc main()
29ebfedea0SLionel Sambuc {
30ebfedea0SLionel Sambuc     unsigned long r[4];
31ebfedea0SLionel Sambuc     sub(r, a, b);
32ebfedea0SLionel Sambuc     fprintf(stderr, "input a= %08X %08X %08X %08X\n", a[3], a[2], a[1], a[0]);
33ebfedea0SLionel Sambuc     fprintf(stderr, "input b= %08X %08X %08X %08X\n", b[3], b[2], b[1], b[0]);
34ebfedea0SLionel Sambuc     fprintf(stderr, "output = %08X %08X %08X %08X\n", r[3], r[2], r[1], r[0]);
35ebfedea0SLionel Sambuc     fprintf(stderr, "correct= %08X %08X %08X %08X\n", c[3], c[2], c[1], c[0]);
36ebfedea0SLionel Sambuc }
37ebfedea0SLionel Sambuc 
sub(r,a,b)38ebfedea0SLionel Sambuc int sub(r, a, b)
39ebfedea0SLionel Sambuc unsigned long *r, *a, *b;
40ebfedea0SLionel Sambuc {
41ebfedea0SLionel Sambuc     register unsigned long t1, t2, *ap, *bp, *rp;
42ebfedea0SLionel Sambuc     int i, carry;
43ebfedea0SLionel Sambuc #ifdef FIXBUG
44ebfedea0SLionel Sambuc     unsigned long dummy;
45ebfedea0SLionel Sambuc #endif
46ebfedea0SLionel Sambuc 
47ebfedea0SLionel Sambuc     ap = a;
48ebfedea0SLionel Sambuc     bp = b;
49ebfedea0SLionel Sambuc     rp = r;
50ebfedea0SLionel Sambuc     carry = 0;
51*0a6a1f1dSLionel Sambuc     for (i = 0; i < 4; i++) {
52ebfedea0SLionel Sambuc         t1 = *(ap++);
53ebfedea0SLionel Sambuc         t2 = *(bp++);
54ebfedea0SLionel Sambuc         t1 = (t1 - t2);
55ebfedea0SLionel Sambuc #ifdef FIXBUG
56ebfedea0SLionel Sambuc         dummy = t1;
57ebfedea0SLionel Sambuc #endif
58ebfedea0SLionel Sambuc         *(rp++) = t1 & 0xffffffff;
59ebfedea0SLionel Sambuc     }
60ebfedea0SLionel Sambuc }
61