Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/whrlpool/wp_dgst.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | int WHIRLPOOL_Init(WHIRLPOOL_CTX *c) | - | ||||||||||||||||||
3 | { | - | ||||||||||||||||||
4 | memset (c,0,sizeof(*c)); | - | ||||||||||||||||||
5 | return never executed: (1);return(1); never executed: return(1); | 0 | ||||||||||||||||||
6 | } | - | ||||||||||||||||||
7 | - | |||||||||||||||||||
8 | int WHIRLPOOL_Update (WHIRLPOOL_CTX *c,const void *_inp,size_t bytes) | - | ||||||||||||||||||
9 | { | - | ||||||||||||||||||
10 | - | |||||||||||||||||||
11 | - | |||||||||||||||||||
12 | - | |||||||||||||||||||
13 | - | |||||||||||||||||||
14 | size_t chunk = ((size_t)1)<<(sizeof(size_t)*8-4); | - | ||||||||||||||||||
15 | const unsigned char *inp = _inp; | - | ||||||||||||||||||
16 | - | |||||||||||||||||||
17 | while (bytes>=chunk
| 0 | ||||||||||||||||||
18 | { | - | ||||||||||||||||||
19 | WHIRLPOOL_BitUpdate(c,inp,chunk*8); | - | ||||||||||||||||||
20 | bytes -= chunk; | - | ||||||||||||||||||
21 | inp += chunk; | - | ||||||||||||||||||
22 | } never executed: end of block | 0 | ||||||||||||||||||
23 | if (bytes
| 0 | ||||||||||||||||||
24 | WHIRLPOOL_BitUpdate(c,inp,bytes*8); never executed: WHIRLPOOL_BitUpdate(c,inp,bytes*8); | 0 | ||||||||||||||||||
25 | - | |||||||||||||||||||
26 | return never executed: (1);return(1); never executed: return(1); | 0 | ||||||||||||||||||
27 | } | - | ||||||||||||||||||
28 | - | |||||||||||||||||||
29 | void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c,const void *_inp,size_t bits) | - | ||||||||||||||||||
30 | { | - | ||||||||||||||||||
31 | size_t n; | - | ||||||||||||||||||
32 | unsigned int bitoff = c->bitoff, | - | ||||||||||||||||||
33 | bitrem = bitoff%8, | - | ||||||||||||||||||
34 | inpgap = (8-(unsigned int)bits%8)&7; | - | ||||||||||||||||||
35 | const unsigned char *inp=_inp; | - | ||||||||||||||||||
36 | - | |||||||||||||||||||
37 | - | |||||||||||||||||||
38 | - | |||||||||||||||||||
39 | - | |||||||||||||||||||
40 | c->bitlen[0] += bits; | - | ||||||||||||||||||
41 | if (c->bitlen[0] < bits
| 0 | ||||||||||||||||||
42 | { | - | ||||||||||||||||||
43 | n = 1; | - | ||||||||||||||||||
44 | do { c->bitlen[n]++; | - | ||||||||||||||||||
45 | } never executed: while(c->bitlen[n]==0end of block
| 0 | ||||||||||||||||||
46 | && ++
| 0 | ||||||||||||||||||
47 | } never executed: end of block | 0 | ||||||||||||||||||
48 | - | |||||||||||||||||||
49 | - | |||||||||||||||||||
50 | reconsider: code before this statement never executed: reconsider: | 0 | ||||||||||||||||||
51 | if (inpgap==0
| 0 | ||||||||||||||||||
52 | { | - | ||||||||||||||||||
53 | while (bits
| 0 | ||||||||||||||||||
54 | { | - | ||||||||||||||||||
55 | if (bitoff==0
| 0 | ||||||||||||||||||
56 | { | - | ||||||||||||||||||
57 | whirlpool_block(c,inp,n); | - | ||||||||||||||||||
58 | inp += n*512/8; | - | ||||||||||||||||||
59 | bits %= 512; | - | ||||||||||||||||||
60 | } never executed: end of block | 0 | ||||||||||||||||||
61 | else | - | ||||||||||||||||||
62 | { | - | ||||||||||||||||||
63 | unsigned int byteoff = bitoff/8; | - | ||||||||||||||||||
64 | - | |||||||||||||||||||
65 | bitrem = 512 - bitoff; | - | ||||||||||||||||||
66 | if (bits >= bitrem
| 0 | ||||||||||||||||||
67 | { | - | ||||||||||||||||||
68 | bits -= bitrem; | - | ||||||||||||||||||
69 | bitrem /= 8; | - | ||||||||||||||||||
70 | memcpy(c->data+byteoff,inp,bitrem); | - | ||||||||||||||||||
71 | inp += bitrem; | - | ||||||||||||||||||
72 | whirlpool_block(c,c->data,1); | - | ||||||||||||||||||
73 | bitoff = 0; | - | ||||||||||||||||||
74 | } never executed: end of block | 0 | ||||||||||||||||||
75 | else | - | ||||||||||||||||||
76 | { | - | ||||||||||||||||||
77 | memcpy(c->data+byteoff,inp,bits/8); | - | ||||||||||||||||||
78 | bitoff += (unsigned int)bits; | - | ||||||||||||||||||
79 | bits = 0; | - | ||||||||||||||||||
80 | } never executed: end of block | 0 | ||||||||||||||||||
81 | c->bitoff = bitoff; | - | ||||||||||||||||||
82 | } never executed: end of block | 0 | ||||||||||||||||||
83 | } | - | ||||||||||||||||||
84 | } never executed: end of block | 0 | ||||||||||||||||||
85 | else | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | { | - | ||||||||||||||||||
88 | while (bits
| 0 | ||||||||||||||||||
89 | { | - | ||||||||||||||||||
90 | unsigned int byteoff = bitoff/8; | - | ||||||||||||||||||
91 | unsigned char b; | - | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | - | |||||||||||||||||||
94 | if (bitrem==inpgap
| 0 | ||||||||||||||||||
95 | { | - | ||||||||||||||||||
96 | c->data[byteoff++] |= inp[0] & (0xff>>inpgap); | - | ||||||||||||||||||
97 | inpgap = 8-inpgap; | - | ||||||||||||||||||
98 | bitoff += inpgap; bitrem = 0; | - | ||||||||||||||||||
99 | bits -= inpgap; inpgap = 0; | - | ||||||||||||||||||
100 | inp++; | - | ||||||||||||||||||
101 | if (bitoff==512
| 0 | ||||||||||||||||||
102 | { | - | ||||||||||||||||||
103 | whirlpool_block(c,c->data,1); | - | ||||||||||||||||||
104 | bitoff = 0; | - | ||||||||||||||||||
105 | } never executed: end of block | 0 | ||||||||||||||||||
106 | c->bitoff = bitoff; | - | ||||||||||||||||||
107 | goto never executed: reconsider;goto reconsider; never executed: goto reconsider; | 0 | ||||||||||||||||||
108 | } | - | ||||||||||||||||||
109 | else | - | ||||||||||||||||||
110 | - | |||||||||||||||||||
111 | if (bits>=8
| 0 | ||||||||||||||||||
112 | { | - | ||||||||||||||||||
113 | b = ((inp[0]<<inpgap) | (inp[1]>>(8-inpgap))); | - | ||||||||||||||||||
114 | b &= 0xff; | - | ||||||||||||||||||
115 | if (bitrem
never executed: c->data[byteoff++] |= b>>bitrem; | 0 | ||||||||||||||||||
116 | else c->data[byteoff++] = b; never executed: c->data[byteoff++] = b; | 0 | ||||||||||||||||||
117 | bitoff += 8; | - | ||||||||||||||||||
118 | bits -= 8; | - | ||||||||||||||||||
119 | inp++; | - | ||||||||||||||||||
120 | if (bitoff>=512
| 0 | ||||||||||||||||||
121 | { | - | ||||||||||||||||||
122 | whirlpool_block(c,c->data,1); | - | ||||||||||||||||||
123 | byteoff = 0; | - | ||||||||||||||||||
124 | bitoff %= 512; | - | ||||||||||||||||||
125 | } never executed: end of block | 0 | ||||||||||||||||||
126 | if (bitrem
never executed: c->data[byteoff] = b<<(8-bitrem); | 0 | ||||||||||||||||||
127 | } never executed: end of block | 0 | ||||||||||||||||||
128 | else | - | ||||||||||||||||||
129 | { | - | ||||||||||||||||||
130 | b = (inp[0]<<inpgap)&0xff; | - | ||||||||||||||||||
131 | if (bitrem
never executed: c->data[byteoff++] |= b>>bitrem; | 0 | ||||||||||||||||||
132 | else c->data[byteoff++] = b; never executed: c->data[byteoff++] = b; | 0 | ||||||||||||||||||
133 | bitoff += (unsigned int)bits; | - | ||||||||||||||||||
134 | if (bitoff==512
| 0 | ||||||||||||||||||
135 | { | - | ||||||||||||||||||
136 | whirlpool_block(c,c->data,1); | - | ||||||||||||||||||
137 | byteoff = 0; | - | ||||||||||||||||||
138 | bitoff %= 512; | - | ||||||||||||||||||
139 | } never executed: end of block | 0 | ||||||||||||||||||
140 | if (bitrem
never executed: c->data[byteoff] = b<<(8-bitrem); | 0 | ||||||||||||||||||
141 | bits = 0; | - | ||||||||||||||||||
142 | } never executed: end of block | 0 | ||||||||||||||||||
143 | c->bitoff = bitoff; | - | ||||||||||||||||||
144 | } never executed: end of block | 0 | ||||||||||||||||||
145 | } never executed: end of block | 0 | ||||||||||||||||||
146 | } | - | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | int WHIRLPOOL_Final (unsigned char *md,WHIRLPOOL_CTX *c) | - | ||||||||||||||||||
149 | { | - | ||||||||||||||||||
150 | unsigned int bitoff = c->bitoff, | - | ||||||||||||||||||
151 | byteoff = bitoff/8; | - | ||||||||||||||||||
152 | size_t i,j,v; | - | ||||||||||||||||||
153 | unsigned char *p; | - | ||||||||||||||||||
154 | - | |||||||||||||||||||
155 | bitoff %= 8; | - | ||||||||||||||||||
156 | if (bitoff
never executed: c->data[byteoff] |= 0x80>>bitoff; | 0 | ||||||||||||||||||
157 | else c->data[byteoff] = 0x80; never executed: c->data[byteoff] = 0x80; | 0 | ||||||||||||||||||
158 | byteoff++; | - | ||||||||||||||||||
159 | - | |||||||||||||||||||
160 | - | |||||||||||||||||||
161 | if (byteoff > (512/8-(256/8))
| 0 | ||||||||||||||||||
162 | { | - | ||||||||||||||||||
163 | if (byteoff<512/8
| 0 | ||||||||||||||||||
164 | memset(&c->data[byteoff],0,512/8-byteoff); never executed: memset(&c->data[byteoff],0,512/8-byteoff); | 0 | ||||||||||||||||||
165 | whirlpool_block(c,c->data,1); | - | ||||||||||||||||||
166 | byteoff = 0; | - | ||||||||||||||||||
167 | } never executed: end of block | 0 | ||||||||||||||||||
168 | if (byteoff < (512/8-(256/8))
| 0 | ||||||||||||||||||
169 | memset(&c->data[byteoff],0, never executed: memset(&c->data[byteoff],0, (512/8-(256/8))-byteoff); | 0 | ||||||||||||||||||
170 | (512/8-(256/8))-byteoff); never executed: memset(&c->data[byteoff],0, (512/8-(256/8))-byteoff); | 0 | ||||||||||||||||||
171 | - | |||||||||||||||||||
172 | p = &c->data[512/8-1]; | - | ||||||||||||||||||
173 | for(i=0;i<(256/8)/sizeof(size_t)
| 0 | ||||||||||||||||||
174 | for(v=c->bitlen[i],j=0;j<sizeof(size_t)
| 0 | ||||||||||||||||||
175 | * never executed: p-- = (unsigned char)(v&0xff);*p-- = (unsigned char)(v&0xff); never executed: *p-- = (unsigned char)(v&0xff); | 0 | ||||||||||||||||||
176 | - | |||||||||||||||||||
177 | whirlpool_block(c,c->data,1); | - | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | if (md
| 0 | ||||||||||||||||||
180 | memcpy(md,c->H.c,(512/8)); | - | ||||||||||||||||||
181 | memset(c,0,sizeof(*c)); | - | ||||||||||||||||||
182 | return never executed: (1);return(1); never executed: return(1); | 0 | ||||||||||||||||||
183 | } | - | ||||||||||||||||||
184 | return never executed: (0);return(0); never executed: return(0); | 0 | ||||||||||||||||||
185 | } | - | ||||||||||||||||||
186 | - | |||||||||||||||||||
187 | unsigned char *WHIRLPOOL(const void *inp, size_t bytes,unsigned char *md) | - | ||||||||||||||||||
188 | { | - | ||||||||||||||||||
189 | WHIRLPOOL_CTX ctx; | - | ||||||||||||||||||
190 | static unsigned char m[(512/8)]; | - | ||||||||||||||||||
191 | - | |||||||||||||||||||
192 | if (md ==
| 0 | ||||||||||||||||||
193 | ((void *)0)
| 0 | ||||||||||||||||||
194 | ) md=m; never executed: md=m; | 0 | ||||||||||||||||||
195 | WHIRLPOOL_Init(&ctx); | - | ||||||||||||||||||
196 | WHIRLPOOL_Update(&ctx,inp,bytes); | - | ||||||||||||||||||
197 | WHIRLPOOL_Final(md,&ctx); | - | ||||||||||||||||||
198 | return never executed: (md);return(md); never executed: return(md); | 0 | ||||||||||||||||||
199 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |