fn crypto_test_hex(value: Bytes) -> Text:
    let alphabet: Text = "0123456789abcdef"
    var result: Text = ""
    var index: Number = 0
    while index < bytes_length(value):
        let byte: Number = bytes_get(value, index)
        let high: Number = byte / 16
        let low: Number = byte % 16
        set result = result + text_slice(alphabet, high, 1) + text_slice(alphabet, low, 1)
        set index = index + 1
    return result

start:
    let digest: Bytes = crypto_sha256(bytes_from_text("abc"))
    assert crypto_test_hex(digest) == "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"

    var hmac_key: Bytes = bytes_from_number(11)
    var repeat_index: Number = 1
    while repeat_index < 20:
        set hmac_key = bytes_concat(hmac_key, bytes_from_number(11))
        set repeat_index = repeat_index + 1
    let hmac: Bytes = crypto_hmac_sha256(hmac_key, bytes_from_text("Hi There"))
    assert crypto_test_hex(hmac) == "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7"
    assert bytes_equal_constant_time(hmac, crypto_hmac_sha256(hmac_key, bytes_from_text("Hi There")))
    assert not bytes_equal_constant_time(hmac, digest)

    var sensitive: Bytes = bytes_from_text("temporary key material")
    let zeroized: Number = bytes_zeroize(sensitive)
    assert zeroized == 0
    assert bytes_get(sensitive, 0) == 0
    assert bytes_get(sensitive, bytes_length(sensitive) - 1) == 0

    let derived_result: Result[Bytes, Text] = crypto_pbkdf2_sha256(bytes_from_text("password"), bytes_from_text("salt"), 1, 32)
    assert result_is_ok(derived_result)
    assert crypto_test_hex(result_unwrap(derived_result)) == "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b"
    assert not result_is_ok(crypto_pbkdf2_sha256(bytes_from_text("password"), bytes_from_text("salt"), 0, 32))
    assert not result_is_ok(crypto_pbkdf2_sha256(bytes_from_text("password"), bytes_from_text("salt"), 1, 65))
