/* Return the 512-bit message digest into the user's array  */
void ICACHE_FLASH_ATTR SHA512_Final(uint8_t *digest, SHA512_CTX *ctx)
/* Return the 512-bit message digest into the user's array  */
void ICACHE_FLASH_ATTR SHA512_Final(uint8_t *digest, SHA512_CTX *ctx)
{
    int i;
    size_t paddingSize;
    uint64_t totalSize;
    uint8_t *padding_ram = malloc(128);
    memcpy(padding_ram, padding, 128);
    totalSize = ctx->totalSize * 8;
    paddingSize = (ctx->size < 112) ? (112 - ctx->size) : 
                                        (128 + 112 - ctx->size);
    SHA512_Update(ctx, padding, paddingSize);
    ctx->w_buf.w[14] = 0;
    ctx->w_buf.w[15] = be64toh(totalSize);
    SHA512_Process(ctx);
    for (i = 0; i < 8; i++)
       ctx->h_dig.h[i] = be64toh(ctx->h_dig.h[i]);
    if (digest != NULL)
       memcpy(digest, ctx->h_dig.digest, SHA512_SIZE);
    free(padding_ram);
 }