CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / tests / test_core_sha_state.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #include "sha256.h" |
| 3 | #include <stdio.h> |
| 4 | #include <string.h> |
| 5 | void ref_sha256_init(sha256_ctx *); |
| 6 | void ref_sha256_update(sha256_ctx *,const uint8_t *,size_t); |
| 7 | void ref_sha256_final(sha256_ctx *,uint8_t *); |
| 8 | int main(void) { |
| 9 | const size_t sizes[]={0,1,3,55,56,63,64,65,119,120,127,128,4095,4096,4097,32768}; |
| 10 | const size_t chunks[]={1,63,64,257,4096}; |
| 11 | uint8_t input[32768],a[32],b[32];memset(input,0x5a,sizeof input); |
| 12 | for(size_t t=0;t<sizeof sizes/sizeof sizes[0];t++)for(size_t k=0;k<sizeof chunks/sizeof chunks[0];k++) { |
| 13 | sha256_ctx x,y;memset(&x,0xa5,sizeof x);y=x; |
| 14 | sha256_init(&x);ref_sha256_init(&y); |
| 15 | for(size_t i=0;i<sizes[t];){size_t n=sizes[t]-i;if(n>chunks[k])n=chunks[k];sha256_update(&x,input+i,n);ref_sha256_update(&y,input+i,n);i+=n;} |
| 16 | for(unsigned final=0;final<2;final++) { |
| 17 | sha256_final(&x,a);ref_sha256_final(&y,b); |
| 18 | if(memcmp(a,b,sizeof a)||memcmp(&x,&y,sizeof x)) { |
| 19 | fprintf(stderr,"SHA context mismatch: size=%zu chunk=%zu final=%u count=%llu reference=%llu\n",sizes[t],chunks[k],final,(unsigned long long)x.count,(unsigned long long)y.count); |
| 20 | return 1; |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | puts("CORE-UTIL SHA context PASS: padding boundaries, chunk splits and repeated finalization");return 0; |
| 25 | } |