int SHA512_Update(SHA512_CTX *c, const void *_data, size_t len)
{
    SHA_LONG64 l;
    unsigned char *p = c->u.p;
    const unsigned char *data = (const unsigned char *)_data;
    if (len == 0)
        return 1;
    l = (c->Nl + (((SHA_LONG64) len) << 3)) & U64(0xffffffffffffffff);
    if (l < c->Nl)
        c->Nh++;
    if (sizeof(len) >= 8)
        c->Nh += (((SHA_LONG64) len) >> 61);
    c->Nl = l;
    if (c->num != 0) {
        size_t n = sizeof(c->u) - c->num;
        if (len < n) {
            memcpy(p + c->num, data, len), c->num += (unsigned int)len;
            return 1;
        } else {
            memcpy(p + c->num, data, n), c->num = 0;
            len -= n, data += n;
            sha512_block_data_order(c, p, 1);
        }
    }
    if (len >= sizeof(c->u)) {
#ifndef SHA512_BLOCK_CAN_MANAGE_UNALIGNED_DATA
        if ((size_t)data % sizeof(c->u.d[0]) != 0)
            while (len >= sizeof(c->u))
                memcpy(p, data, sizeof(c->u)),
                sha512_block_data_order(c, p, 1),
                len -= sizeof(c->u), data += sizeof(c->u);
        else
#endif
            sha512_block_data_order(c, data, len / sizeof(c->u)),
            data += len, len %= sizeof(c->u), data -= len;
    }
    if (len != 0)
        memcpy(p, data, len), c->num = (int)len;
    return 1;
}
['int ED25519_sign(uint8_t *out_sig, const uint8_t *message, size_t message_len,\n                 const uint8_t public_key[32], const uint8_t private_key[32]) {\n  uint8_t az[SHA512_DIGEST_LENGTH];\n  uint8_t nonce[SHA512_DIGEST_LENGTH];\n  ge_p3 R;\n  uint8_t hram[SHA512_DIGEST_LENGTH];\n  SHA512_CTX hash_ctx;\n  SHA512_Init(&hash_ctx);\n  SHA512_Update(&hash_ctx, private_key, 32);\n  SHA512_Final(az, &hash_ctx);\n  az[0] &= 248;\n  az[31] &= 63;\n  az[31] |= 64;\n  SHA512_Init(&hash_ctx);\n  SHA512_Update(&hash_ctx, az + 32, 32);\n  SHA512_Update(&hash_ctx, message, message_len);\n  SHA512_Final(nonce, &hash_ctx);\n  x25519_sc_reduce(nonce);\n  ge_scalarmult_base(&R, nonce);\n  ge_p3_tobytes(out_sig, &R);\n  SHA512_Init(&hash_ctx);\n  SHA512_Update(&hash_ctx, out_sig, 32);\n  SHA512_Update(&hash_ctx, public_key, 32);\n  SHA512_Update(&hash_ctx, message, message_len);\n  SHA512_Final(hram, &hash_ctx);\n  x25519_sc_reduce(hram);\n  sc_muladd(out_sig + 32, hram, az, nonce);\n  OPENSSL_cleanse(&hash_ctx, sizeof(hash_ctx));\n  OPENSSL_cleanse(nonce, sizeof(nonce));\n  OPENSSL_cleanse(az, sizeof(az));\n  return 1;\n}', 'int SHA512_Init(SHA512_CTX *c)\n{\n    c->h[0] = U64(0x6a09e667f3bcc908);\n    c->h[1] = U64(0xbb67ae8584caa73b);\n    c->h[2] = U64(0x3c6ef372fe94f82b);\n    c->h[3] = U64(0xa54ff53a5f1d36f1);\n    c->h[4] = U64(0x510e527fade682d1);\n    c->h[5] = U64(0x9b05688c2b3e6c1f);\n    c->h[6] = U64(0x1f83d9abfb41bd6b);\n    c->h[7] = U64(0x5be0cd19137e2179);\n    c->Nl = 0;\n    c->Nh = 0;\n    c->num = 0;\n    c->md_len = SHA512_DIGEST_LENGTH;\n    return 1;\n}', 'int SHA512_Update(SHA512_CTX *c, const void *_data, size_t len)\n{\n    SHA_LONG64 l;\n    unsigned char *p = c->u.p;\n    const unsigned char *data = (const unsigned char *)_data;\n    if (len == 0)\n        return 1;\n    l = (c->Nl + (((SHA_LONG64) len) << 3)) & U64(0xffffffffffffffff);\n    if (l < c->Nl)\n        c->Nh++;\n    if (sizeof(len) >= 8)\n        c->Nh += (((SHA_LONG64) len) >> 61);\n    c->Nl = l;\n    if (c->num != 0) {\n        size_t n = sizeof(c->u) - c->num;\n        if (len < n) {\n            memcpy(p + c->num, data, len), c->num += (unsigned int)len;\n            return 1;\n        } else {\n            memcpy(p + c->num, data, n), c->num = 0;\n            len -= n, data += n;\n            sha512_block_data_order(c, p, 1);\n        }\n    }\n    if (len >= sizeof(c->u)) {\n#ifndef SHA512_BLOCK_CAN_MANAGE_UNALIGNED_DATA\n        if ((size_t)data % sizeof(c->u.d[0]) != 0)\n            while (len >= sizeof(c->u))\n                memcpy(p, data, sizeof(c->u)),\n                sha512_block_data_order(c, p, 1),\n                len -= sizeof(c->u), data += sizeof(c->u);\n        else\n#endif\n            sha512_block_data_order(c, data, len / sizeof(c->u)),\n            data += len, len %= sizeof(c->u), data -= len;\n    }\n    if (len != 0)\n        memcpy(p, data, len), c->num = (int)len;\n    return 1;\n}']