OpenCoverage

sha512.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/sha/sha512.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11-
12-
13-
14-
15-
16int SHA384_Init(SHA512_CTX *c)-
17 {-
18 c->h[0]=0xcbbb9d5dc1059ed8UL;-
19 c->h[1]=0x629a292a367cd507UL;-
20 c->h[2]=0x9159015a3070dd17UL;-
21 c->h[3]=0x152fecd8f70e5939UL;-
22 c->h[4]=0x67332667ffc00b31UL;-
23 c->h[5]=0x8eb44a8768581511UL;-
24 c->h[6]=0xdb0c2e0d64f98fa7UL;-
25 c->h[7]=0x47b5481dbefa4fa4UL;-
26-
27 c->Nl=0; c->Nh=0;-
28 c->num=0; c->md_len=48;-
29 return
executed 1196 times by 4 tests: return 1;
Executed by:
  • servertest
  • sha512test
  • ssltest
  • tls_prf
1;
executed 1196 times by 4 tests: return 1;
Executed by:
  • servertest
  • sha512test
  • ssltest
  • tls_prf
1196
30 }-
31-
32int SHA512_Init(SHA512_CTX *c)-
33 {-
34 c->h[0]=0x6a09e667f3bcc908UL;-
35 c->h[1]=0xbb67ae8584caa73bUL;-
36 c->h[2]=0x3c6ef372fe94f82bUL;-
37 c->h[3]=0xa54ff53a5f1d36f1UL;-
38 c->h[4]=0x510e527fade682d1UL;-
39 c->h[5]=0x9b05688c2b3e6c1fUL;-
40 c->h[6]=0x1f83d9abfb41bd6bUL;-
41 c->h[7]=0x5be0cd19137e2179UL;-
42-
43 c->Nl=0; c->Nh=0;-
44 c->num=0; c->md_len=64;-
45 return
executed 77 times by 4 tests: return 1;
Executed by:
  • pbkdf2
  • sha512test
  • ssltest
  • tlstest
1;
executed 77 times by 4 tests: return 1;
Executed by:
  • pbkdf2
  • sha512test
  • ssltest
  • tlstest
77
46 }-
47-
48-
49-
50-
51void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num);-
52-
53int SHA512_Final (unsigned char *md, SHA512_CTX *c)-
54 {-
55 unsigned char *p=(unsigned char *)c->u.p;-
56 size_t n=c->num;-
57-
58 p[n]=0x80;-
59 n++;-
60 if (n > (sizeof(c->u)-16)
n > (sizeof(c->u)-16)Description
TRUEevaluated 270 times by 3 tests
Evaluated by:
  • sha512test
  • ssltest
  • tls_prf
FALSEevaluated 25590 times by 5 tests
Evaluated by:
  • pbkdf2
  • sha512test
  • ssltest
  • tls_prf
  • tlstest
)
270-25590
61 memset (p+n,0,sizeof(c->u)-n), n=0,
executed 270 times by 3 tests: memset (p+n,0,sizeof(c->u)-n), n=0, sha512_block_data_order (c,p,1);
Executed by:
  • sha512test
  • ssltest
  • tls_prf
270
62 sha512_block_data_order (c,p,1);
executed 270 times by 3 tests: memset (p+n,0,sizeof(c->u)-n), n=0, sha512_block_data_order (c,p,1);
Executed by:
  • sha512test
  • ssltest
  • tls_prf
270
63-
64 memset (p+n,0,sizeof(c->u)-16-n);-
65-
66-
67-
68-
69 p[sizeof(c->u)-1] = (unsigned char)(c->Nl);-
70 p[sizeof(c->u)-2] = (unsigned char)(c->Nl>>8);-
71 p[sizeof(c->u)-3] = (unsigned char)(c->Nl>>16);-
72 p[sizeof(c->u)-4] = (unsigned char)(c->Nl>>24);-
73 p[sizeof(c->u)-5] = (unsigned char)(c->Nl>>32);-
74 p[sizeof(c->u)-6] = (unsigned char)(c->Nl>>40);-
75 p[sizeof(c->u)-7] = (unsigned char)(c->Nl>>48);-
76 p[sizeof(c->u)-8] = (unsigned char)(c->Nl>>56);-
77 p[sizeof(c->u)-9] = (unsigned char)(c->Nh);-
78 p[sizeof(c->u)-10] = (unsigned char)(c->Nh>>8);-
79 p[sizeof(c->u)-11] = (unsigned char)(c->Nh>>16);-
80 p[sizeof(c->u)-12] = (unsigned char)(c->Nh>>24);-
81 p[sizeof(c->u)-13] = (unsigned char)(c->Nh>>32);-
82 p[sizeof(c->u)-14] = (unsigned char)(c->Nh>>40);-
83 p[sizeof(c->u)-15] = (unsigned char)(c->Nh>>48);-
84 p[sizeof(c->u)-16] = (unsigned char)(c->Nh>>56);-
85-
86-
87 sha512_block_data_order (c,p,1);-
88-
89 if (md==0
md==0Description
TRUEnever evaluated
FALSEevaluated 25860 times by 5 tests
Evaluated by:
  • pbkdf2
  • sha512test
  • ssltest
  • tls_prf
  • tlstest
) return
never executed: return 0;
0;
never executed: return 0;
0-25860
90-
91 switch (c->md_len)-
92 {-
93-
94 case
executed 1211 times by 3 tests: case 48:
Executed by:
  • sha512test
  • ssltest
  • tls_prf
48:
executed 1211 times by 3 tests: case 48:
Executed by:
  • sha512test
  • ssltest
  • tls_prf
1211
95 for (n=0;n<48/8
n<48/8Description
TRUEevaluated 7266 times by 3 tests
Evaluated by:
  • sha512test
  • ssltest
  • tls_prf
FALSEevaluated 1211 times by 3 tests
Evaluated by:
  • sha512test
  • ssltest
  • tls_prf
;n++)
1211-7266
96 {-
97 unsigned long t = c->h[n];-
98-
99 *(md++) = (unsigned char)(t>>56);-
100 *(md++) = (unsigned char)(t>>48);-
101 *(md++) = (unsigned char)(t>>40);-
102 *(md++) = (unsigned char)(t>>32);-
103 *(md++) = (unsigned char)(t>>24);-
104 *(md++) = (unsigned char)(t>>16);-
105 *(md++) = (unsigned char)(t>>8);-
106 *(md++) = (unsigned char)(t);-
107 }
executed 7266 times by 3 tests: end of block
Executed by:
  • sha512test
  • ssltest
  • tls_prf
7266
108 break;
executed 1211 times by 3 tests: break;
Executed by:
  • sha512test
  • ssltest
  • tls_prf
1211
109 case
executed 24649 times by 4 tests: case 64:
Executed by:
  • pbkdf2
  • sha512test
  • ssltest
  • tlstest
64:
executed 24649 times by 4 tests: case 64:
Executed by:
  • pbkdf2
  • sha512test
  • ssltest
  • tlstest
24649
110 for (n=0;n<64/8
n<64/8Description
TRUEevaluated 197192 times by 4 tests
Evaluated by:
  • pbkdf2
  • sha512test
  • ssltest
  • tlstest
FALSEevaluated 24649 times by 4 tests
Evaluated by:
  • pbkdf2
  • sha512test
  • ssltest
  • tlstest
;n++)
24649-197192
111 {-
112 unsigned long t = c->h[n];-
113-
114 *(md++) = (unsigned char)(t>>56);-
115 *(md++) = (unsigned char)(t>>48);-
116 *(md++) = (unsigned char)(t>>40);-
117 *(md++) = (unsigned char)(t>>32);-
118 *(md++) = (unsigned char)(t>>24);-
119 *(md++) = (unsigned char)(t>>16);-
120 *(md++) = (unsigned char)(t>>8);-
121 *(md++) = (unsigned char)(t);-
122 }
executed 197192 times by 4 tests: end of block
Executed by:
  • pbkdf2
  • sha512test
  • ssltest
  • tlstest
197192
123 break;
executed 24649 times by 4 tests: break;
Executed by:
  • pbkdf2
  • sha512test
  • ssltest
  • tlstest
24649
124-
125 default
never executed: default:
:
never executed: default:
return
never executed: return 0;
0;
never executed: return 0;
0
126 }-
127-
128 return
executed 25860 times by 5 tests: return 1;
Executed by:
  • pbkdf2
  • sha512test
  • ssltest
  • tls_prf
  • tlstest
1;
executed 25860 times by 5 tests: return 1;
Executed by:
  • pbkdf2
  • sha512test
  • ssltest
  • tls_prf
  • tlstest
25860
129 }-
130-
131int SHA384_Final (unsigned char *md,SHA512_CTX *c)-
132{ return
never executed: return SHA512_Final (md,c);
SHA512_Final (md,c);
never executed: return SHA512_Final (md,c);
}
0
133-
134int SHA512_Update (SHA512_CTX *c, const void *_data, size_t len)-
135 {-
136 unsigned long l;-
137 unsigned char *p=c->u.p;-
138 const unsigned char *data=(const unsigned char *)_data;-
139-
140 if (len==0
len==0Description
TRUEnever evaluated
FALSEevaluated 48212 times by 6 tests
Evaluated by:
  • pbkdf2
  • servertest
  • sha512test
  • ssltest
  • tls_prf
  • tlstest
) return
never executed: return 1;
1;
never executed: return 1;
0-48212
141-
142 l = (c->Nl+(((unsigned long)len)<<3))&0xffffffffffffffffUL;-
143 if (l < c->Nl
l < c->NlDescription
TRUEnever evaluated
FALSEevaluated 48212 times by 6 tests
Evaluated by:
  • pbkdf2
  • servertest
  • sha512test
  • ssltest
  • tls_prf
  • tlstest
) c->Nh++;
never executed: c->Nh++;
0-48212
144 if (sizeof(len)>=8
sizeof(len)>=8Description
TRUEevaluated 48212 times by 6 tests
Evaluated by:
  • pbkdf2
  • servertest
  • sha512test
  • ssltest
  • tls_prf
  • tlstest
FALSEnever evaluated
) c->Nh+=(((unsigned long)len)>>61);
executed 48212 times by 6 tests: c->Nh+=(((unsigned long)len)>>61);
Executed by:
  • pbkdf2
  • servertest
  • sha512test
  • ssltest
  • tls_prf
  • tlstest
0-48212
145 c->Nl=l;-
146-
147 if (c->num != 0
c->num != 0Description
TRUEevaluated 12497 times by 6 tests
Evaluated by:
  • pbkdf2
  • servertest
  • sha512test
  • ssltest
  • tls_prf
  • tlstest
FALSEevaluated 35715 times by 6 tests
Evaluated by:
  • pbkdf2
  • servertest
  • sha512test
  • ssltest
  • tls_prf
  • tlstest
)
12497-35715
148 {-
149 size_t n = sizeof(c->u) - c->num;-
150-
151 if (len < n
len < nDescription
TRUEevaluated 2002 times by 5 tests
Evaluated by:
  • pbkdf2
  • servertest
  • ssltest
  • tls_prf
  • tlstest
FALSEevaluated 10495 times by 3 tests
Evaluated by:
  • servertest
  • sha512test
  • ssltest
)
2002-10495
152 {-
153 memcpy (p+c->num,data,len), c->num += (unsigned int)len;-
154 return
executed 2002 times by 5 tests: return 1;
Executed by:
  • pbkdf2
  • servertest
  • ssltest
  • tls_prf
  • tlstest
1;
executed 2002 times by 5 tests: return 1;
Executed by:
  • pbkdf2
  • servertest
  • ssltest
  • tls_prf
  • tlstest
2002
155 }-
156 else {-
157 memcpy (p+c->num,data,n), c->num = 0;-
158 len-=n, data+=n;-
159 sha512_block_data_order (c,p,1);-
160 }
executed 10495 times by 3 tests: end of block
Executed by:
  • servertest
  • sha512test
  • ssltest
10495
161 }-
162-
163 if (len >= sizeof(c->u)
len >= sizeof(c->u)Description
TRUEevaluated 4719 times by 5 tests
Evaluated by:
  • pbkdf2
  • servertest
  • sha512test
  • ssltest
  • tls_prf
FALSEevaluated 41491 times by 6 tests
Evaluated by:
  • pbkdf2
  • servertest
  • sha512test
  • ssltest
  • tls_prf
  • tlstest
)
4719-41491
164 {-
165 sha512_block_data_order (c,data,len/sizeof(c->u)),-
166 data += len,-
167 len %= sizeof(c->u),-
168 data -= len;-
169 }
executed 4719 times by 5 tests: end of block
Executed by:
  • pbkdf2
  • servertest
  • sha512test
  • ssltest
  • tls_prf
4719
170-
171 if (len != 0
len != 0Description
TRUEevaluated 36340 times by 6 tests
Evaluated by:
  • pbkdf2
  • servertest
  • sha512test
  • ssltest
  • tls_prf
  • tlstest
FALSEevaluated 9870 times by 4 tests
Evaluated by:
  • pbkdf2
  • sha512test
  • ssltest
  • tls_prf
) memcpy (p,data,len), c->num = (int)len;
executed 36340 times by 6 tests: memcpy (p,data,len), c->num = (int)len;
Executed by:
  • pbkdf2
  • servertest
  • sha512test
  • ssltest
  • tls_prf
  • tlstest
9870-36340
172-
173 return
executed 46210 times by 6 tests: return 1;
Executed by:
  • pbkdf2
  • servertest
  • sha512test
  • ssltest
  • tls_prf
  • tlstest
1;
executed 46210 times by 6 tests: return 1;
Executed by:
  • pbkdf2
  • servertest
  • sha512test
  • ssltest
  • tls_prf
  • tlstest
46210
174 }-
175-
176int SHA384_Update (SHA512_CTX *c, const void *data, size_t len)-
177{ return
never executed: return SHA512_Update (c,data,len);
SHA512_Update (c,data,len);
never executed: return SHA512_Update (c,data,len);
}
0
178-
179void SHA512_Transform (SHA512_CTX *c, const unsigned char *data)-
180 {-
181-
182-
183-
184-
185-
186 sha512_block_data_order (c,data,1);-
187 }
executed 32 times by 1 test: end of block
Executed by:
  • ssltest
32
188-
189unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md)-
190 {-
191 SHA512_CTX c;-
192 static unsigned char m[48];-
193-
194 if (md ==
md == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
195 ((void *)0)
md == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
196 ) md=m;
never executed: md=m;
0
197 SHA384_Init(&c);-
198 SHA512_Update(&c,d,n);-
199 SHA512_Final(md,&c);-
200 explicit_bzero(&c,sizeof(c));-
201 return
never executed: return(md);
(md);
never executed: return(md);
0
202 }-
203-
204unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md)-
205 {-
206 SHA512_CTX c;-
207 static unsigned char m[64];-
208-
209 if (md ==
md == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
210 ((void *)0)
md == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
211 ) md=m;
never executed: md=m;
0
212 SHA512_Init(&c);-
213 SHA512_Update(&c,d,n);-
214 SHA512_Final(md,&c);-
215 explicit_bzero(&c,sizeof(c));-
216 return
never executed: return(md);
(md);
never executed: return(md);
0
217 }-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2