cardano-crypto-praos/cbits/vrf10_batchcompat/convert.c
int
_vrf_ietfdraft10_hash_to_curve_try_inc(unsigned char H_string[crypto_core_ed25519_BYTES],
                                       const ge25519_p3 *Y_point,
                                       const unsigned char *alpha,
                                       const unsigned long long alphalen)
{
    unsigned char            Y_string[crypto_vrf_ietfdraft10_PUBLICKEYBYTES], r_string[crypto_hash_sha512_BYTES];

    _vrf_ietfdraft10_point_to_string(Y_string, Y_point);

    ge25519_p3 p3;
    int check = TAI_NR_TRIES;
    unsigned char value = ZERO;
    while (check > 0) {
        crypto_hash_sha512_state hs;
        crypto_hash_sha512_init(&hs);
        crypto_hash_sha512_update(&hs, &SUITE, 1);
        crypto_hash_sha512_update(&hs, &ONE, 1);
        crypto_hash_sha512_update(&hs, Y_string, crypto_vrf_ietfdraft10_PUBLICKEYBYTES);
        crypto_hash_sha512_update(&hs, alpha, alphalen);
        crypto_hash_sha512_update(&hs, &value, 1);
        crypto_hash_sha512_update(&hs, &ZERO, 1);
        crypto_hash_sha512_final(&hs, r_string);

        if (ge25519_frombytes(&p3, r_string) == 0) {
            multiply_by_cofactor(&p3);
            ge25519_p3_tobytes(H_string, &p3);
            return 0;
        };

        value += ONE;
        check -= 1;
    }

    return -1;
}
/*
 * Computing the `hash_to_curve` using try and increment. In order to make the
 * function always terminate, we bound  the number of tries to `TAI_NR_TRIES`.
 * If the try `TAI_NR_TRIES` fails, which happens with probability around 1/2^32,
 * this returns an error (-1). This diverges from the standard: the latter describes
 * the function with an infinite loop.
 */
Computing the `hash_to_curve` using try and increment. In order to make the
function always terminate, we bound  the number of tries to `TAI_NR_TRIES`.
If the try `TAI_NR_TRIES` fails, which happens with probability around 1/2^32,
this returns an error (-1). This diverges from the standard: the latter describes
the function with an infinite loop.
Computing the ` hash_to_curve ` using try and increment . In order to make the function always terminate we bound the number of tries to ` TAI_NR_TRIES ` . If the try ` TAI_NR_TRIES ` fails which happens with probability around 1 / 2^32 this returns an error ( - 1 ) . This diverges from the standard : the latter describes the function with an infinite loop .
int
_vrf_ietfdraft10_hash_to_curve_try_inc(unsigned char H_string[crypto_core_ed25519_BYTES],
                                       const ge25519_p3 *Y_point,
                                       const unsigned char *alpha,
                                       const unsigned long long alphalen)
{
    unsigned char            Y_string[crypto_vrf_ietfdraft10_PUBLICKEYBYTES], r_string[crypto_hash_sha512_BYTES];
    _vrf_ietfdraft10_point_to_string(Y_string, Y_point);
    ge25519_p3 p3;
    int check = TAI_NR_TRIES;
    unsigned char value = ZERO;
    while (check > 0) {
        crypto_hash_sha512_state hs;
        crypto_hash_sha512_init(&hs);
        crypto_hash_sha512_update(&hs, &SUITE, 1);
        crypto_hash_sha512_update(&hs, &ONE, 1);
        crypto_hash_sha512_update(&hs, Y_string, crypto_vrf_ietfdraft10_PUBLICKEYBYTES);
        crypto_hash_sha512_update(&hs, alpha, alphalen);
        crypto_hash_sha512_update(&hs, &value, 1);
        crypto_hash_sha512_update(&hs, &ZERO, 1);
        crypto_hash_sha512_final(&hs, r_string);
        if (ge25519_frombytes(&p3, r_string) == 0) {
            multiply_by_cofactor(&p3);
            ge25519_p3_tobytes(H_string, &p3);
            return 0;
        };
        value += ONE;
        check -= 1;
    }
    return -1;
}
int _vrf_ietfdraft10_hash_to_curve_try_inc ( unsigned char H_string [ crypto_core_ed25519_BYTES ] , const ge25519_p3 * Y_point , const unsigned char * alpha , const unsigned long long alphalen ) { unsigned char Y_string [ crypto_vrf_ietfdraft10_PUBLICKEYBYTES ] , r_string [ crypto_hash_sha512_BYTES ] ; _vrf_ietfdraft10_point_to_string ( Y_string , Y_point ) ; ge25519_p3 p3 ; int check = TAI_NR_TRIES ; unsigned char value = ZERO ; while ( check > 0 ) { crypto_hash_sha512_state hs ; crypto_hash_sha512_init ( & hs ) ; crypto_hash_sha512_update ( & hs , & SUITE , 1 ) ; crypto_hash_sha512_update ( & hs , & ONE , 1 ) ; crypto_hash_sha512_update ( & hs , Y_string , crypto_vrf_ietfdraft10_PUBLICKEYBYTES ) ; crypto_hash_sha512_update ( & hs , alpha , alphalen ) ; crypto_hash_sha512_update ( & hs , & value , 1 ) ; crypto_hash_sha512_update ( & hs , & ZERO , 1 ) ; crypto_hash_sha512_final ( & hs , r_string ) ; if ( ge25519_frombytes ( & p3 , r_string ) == 0 ) { multiply_by_cofactor ( & p3 ) ; ge25519_p3_tobytes ( H_string , & p3 ) ; return 0 ; } ; value += ONE ; check -= 1 ; } return -1 ; }
Computing the `hash_to_curve` using try and increment.
Computing the ` hash_to_curve ` using try and increment .