ext/iodine/fio.c
/**
Initialize/reset the SHA-2 object.

SHA-2 is actually a family of functions with different variants. When
initializing the SHA-2 container, you must select the variant you intend to
apply. The following are valid options (see the fio_sha2_variant_e enum):

- SHA_512 (== 0)
- SHA_384
- SHA_512_224
- SHA_512_256
- SHA_256
- SHA_224

*/
Initialize/reset the SHA-2 object.
SHA-2 is actually a family of functions with different variants. When
initializing the SHA-2 container, you must select the variant you intend to
apply. The following are valid options .


Initialize / reset the SHA - 2 object . SHA - 2 is actually a family of functions with different variants . When initializing the SHA - 2 container you must select the variant you intend to apply . The following are valid options .
fio_sha2_s fio_sha2_init(fio_sha2_variant_e variant) {
  if (variant == SHA_256) {
    return (fio_sha2_s){
        .type = SHA_256,
        .digest.i32[0] = 0x6a09e667,
        .digest.i32[1] = 0xbb67ae85,
        .digest.i32[2] = 0x3c6ef372,
        .digest.i32[3] = 0xa54ff53a,
        .digest.i32[4] = 0x510e527f,
        .digest.i32[5] = 0x9b05688c,
        .digest.i32[6] = 0x1f83d9ab,
        .digest.i32[7] = 0x5be0cd19,
    };
  } else if (variant == SHA_384) {
    return (fio_sha2_s){
        .type = SHA_384,
        .digest.i64[0] = 0xcbbb9d5dc1059ed8,
        .digest.i64[1] = 0x629a292a367cd507,
        .digest.i64[2] = 0x9159015a3070dd17,
        .digest.i64[3] = 0x152fecd8f70e5939,
        .digest.i64[4] = 0x67332667ffc00b31,
        .digest.i64[5] = 0x8eb44a8768581511,
        .digest.i64[6] = 0xdb0c2e0d64f98fa7,
        .digest.i64[7] = 0x47b5481dbefa4fa4,
    };
  } else if (variant == SHA_512) {
    return (fio_sha2_s){
        .type = SHA_512,
        .digest.i64[0] = 0x6a09e667f3bcc908,
        .digest.i64[1] = 0xbb67ae8584caa73b,
        .digest.i64[2] = 0x3c6ef372fe94f82b,
        .digest.i64[3] = 0xa54ff53a5f1d36f1,
        .digest.i64[4] = 0x510e527fade682d1,
        .digest.i64[5] = 0x9b05688c2b3e6c1f,
        .digest.i64[6] = 0x1f83d9abfb41bd6b,
        .digest.i64[7] = 0x5be0cd19137e2179,
    };
  } else if (variant == SHA_224) {
    return (fio_sha2_s){
        .type = SHA_224,
        .digest.i32[0] = 0xc1059ed8,
        .digest.i32[1] = 0x367cd507,
        .digest.i32[2] = 0x3070dd17,
        .digest.i32[3] = 0xf70e5939,
        .digest.i32[4] = 0xffc00b31,
        .digest.i32[5] = 0x68581511,
        .digest.i32[6] = 0x64f98fa7,
        .digest.i32[7] = 0xbefa4fa4,
    };
  } else if (variant == SHA_512_224) {
    return (fio_sha2_s){
        .type = SHA_512_224,
        .digest.i64[0] = 0x8c3d37c819544da2,
        .digest.i64[1] = 0x73e1996689dcd4d6,
        .digest.i64[2] = 0x1dfab7ae32ff9c82,
        .digest.i64[3] = 0x679dd514582f9fcf,
        .digest.i64[4] = 0x0f6d2b697bd44da8,
        .digest.i64[5] = 0x77e36f7304c48942,
        .digest.i64[6] = 0x3f9d85a86a1d36c8,
        .digest.i64[7] = 0x1112e6ad91d692a1,
    };
  } else if (variant == SHA_512_256) {
    return (fio_sha2_s){
        .type = SHA_512_256,
        .digest.i64[0] = 0x22312194fc2bf72c,
        .digest.i64[1] = 0x9f555fa3c84c64c2,
        .digest.i64[2] = 0x2393b86b6f53b151,
        .digest.i64[3] = 0x963877195940eabd,
        .digest.i64[4] = 0x96283ee2a88effe3,
        .digest.i64[5] = 0xbe5e1e2553863992,
        .digest.i64[6] = 0x2b0199fc2c85b8aa,
        .digest.i64[7] = 0x0eb72ddc81c52ca2,
    };
  }
  FIO_LOG_FATAL("SHA-2 ERROR - variant unknown");
  exit(2);
}
fio_sha2_s fio_sha2_init ( fio_sha2_variant_e variant ) { if ( variant == SHA_256 ) { return ( fio_sha2_s ) { . type = SHA_256 , . digest . i32 [ 0 ] = 0x6a09e667 , . digest . i32 [ 1 ] = 0xbb67ae85 , . digest . i32 [ 2 ] = 0x3c6ef372 , . digest . i32 [ 3 ] = 0xa54ff53a , . digest . i32 [ 4 ] = 0x510e527f , . digest . i32 [ 5 ] = 0x9b05688c , . digest . i32 [ 6 ] = 0x1f83d9ab , . digest . i32 [ 7 ] = 0x5be0cd19 , } ; } else if ( variant == SHA_384 ) { return ( fio_sha2_s ) { . type = SHA_384 , . digest . i64 [ 0 ] = 0xcbbb9d5dc1059ed8 , . digest . i64 [ 1 ] = 0x629a292a367cd507 , . digest . i64 [ 2 ] = 0x9159015a3070dd17 , . digest . i64 [ 3 ] = 0x152fecd8f70e5939 , . digest . i64 [ 4 ] = 0x67332667ffc00b31 , . digest . i64 [ 5 ] = 0x8eb44a8768581511 , . digest . i64 [ 6 ] = 0xdb0c2e0d64f98fa7 , . digest . i64 [ 7 ] = 0x47b5481dbefa4fa4 , } ; } else if ( variant == SHA_512 ) { return ( fio_sha2_s ) { . type = SHA_512 , . digest . i64 [ 0 ] = 0x6a09e667f3bcc908 , . digest . i64 [ 1 ] = 0xbb67ae8584caa73b , . digest . i64 [ 2 ] = 0x3c6ef372fe94f82b , . digest . i64 [ 3 ] = 0xa54ff53a5f1d36f1 , . digest . i64 [ 4 ] = 0x510e527fade682d1 , . digest . i64 [ 5 ] = 0x9b05688c2b3e6c1f , . digest . i64 [ 6 ] = 0x1f83d9abfb41bd6b , . digest . i64 [ 7 ] = 0x5be0cd19137e2179 , } ; } else if ( variant == SHA_224 ) { return ( fio_sha2_s ) { . type = SHA_224 , . digest . i32 [ 0 ] = 0xc1059ed8 , . digest . i32 [ 1 ] = 0x367cd507 , . digest . i32 [ 2 ] = 0x3070dd17 , . digest . i32 [ 3 ] = 0xf70e5939 , . digest . i32 [ 4 ] = 0xffc00b31 , . digest . i32 [ 5 ] = 0x68581511 , . digest . i32 [ 6 ] = 0x64f98fa7 , . digest . i32 [ 7 ] = 0xbefa4fa4 , } ; } else if ( variant == SHA_512_224 ) { return ( fio_sha2_s ) { . type = SHA_512_224 , . digest . i64 [ 0 ] = 0x8c3d37c819544da2 , . digest . i64 [ 1 ] = 0x73e1996689dcd4d6 , . digest . i64 [ 2 ] = 0x1dfab7ae32ff9c82 , . digest . i64 [ 3 ] = 0x679dd514582f9fcf , . digest . i64 [ 4 ] = 0x0f6d2b697bd44da8 , . digest . i64 [ 5 ] = 0x77e36f7304c48942 , . digest . i64 [ 6 ] = 0x3f9d85a86a1d36c8 , . digest . i64 [ 7 ] = 0x1112e6ad91d692a1 , } ; } else if ( variant == SHA_512_256 ) { return ( fio_sha2_s ) { . type = SHA_512_256 , . digest . i64 [ 0 ] = 0x22312194fc2bf72c , . digest . i64 [ 1 ] = 0x9f555fa3c84c64c2 , . digest . i64 [ 2 ] = 0x2393b86b6f53b151 , . digest . i64 [ 3 ] = 0x963877195940eabd , . digest . i64 [ 4 ] = 0x96283ee2a88effe3 , . digest . i64 [ 5 ] = 0xbe5e1e2553863992 , . digest . i64 [ 6 ] = 0x2b0199fc2c85b8aa , . digest . i64 [ 7 ] = 0x0eb72ddc81c52ca2 , } ; } FIO_LOG_FATAL ( " " ) ; exit ( 2 ) ; }
Initialize/reset the SHA-2 object.
Initialize / reset the SHA - 2 object .