// File: msotoodeh[P]asymmetric-passwords/common/curve25519/ed25519_verify.c
// Function: ed25519_Verify_Init
void * ed25519_Verify_Init(
    void *context,                      /* IO: null or context buffer to use */
    const unsigned char *publicKey)     /* IN: [32 bytes] public key */
{
    int i;
    Ext_POINT Q, T;
    EDP_SIGV_CTX *ctx = (EDP_SIGV_CTX*)context;

    if (ctx == 0) ctx = (EDP_SIGV_CTX*)mem_alloc(sizeof(EDP_SIGV_CTX));

    if (ctx)
    {
        memcpy(ctx->pk, publicKey, 32);
        i = ecp_DecodeInt(Q.y, publicKey);
        ed25519_CalculateX(Q.x, Q.y, ~i);       /* Invert parity for -Q */
        ecp_MulMod(Q.t, Q.x, Q.y);
        ecp_SetValue(Q.z, 1);

        /* pre-compute q-table */

        /* Calculate: Q0=Q, Q1=(2^64)*Q, Q2=(2^128)*Q, Q3=(2^192)*Q */

        ecp_SetValue(ctx->q_table[0].YpX, 1);           /* -- -- -- -- */
        ecp_SetValue(ctx->q_table[0].YmX, 1);
        ecp_SetValue(ctx->q_table[0].T2d, 0);
        ecp_SetValue(ctx->q_table[0].Z2, 2);

        edp_ExtPoint2PE(&ctx->q_table[1], &Q);          /* -- -- -- q0 */

        for (i = 0; i < 64; i++) edp_DoublePoint(&Q);

        edp_ExtPoint2PE(&ctx->q_table[2], &Q);          /* -- -- q1 -- */
        QTABLE_SET(3,1);                                /* -- -- q1 q0 */

        do edp_DoublePoint(&Q); while (++i < 128);

        edp_ExtPoint2PE(&ctx->q_table[4], &Q);          /* -- q2 -- -- */
        QTABLE_SET(5, 1);                               /* -- q2 -- q0 */
        QTABLE_SET(6, 2);                               /* -- q2 q1 -- */
        QTABLE_SET(7, 3);                               /* -- q2 q1 q0 */

        do edp_DoublePoint(&Q); while (++i < 192);

        edp_ExtPoint2PE(&ctx->q_table[8], &Q);          /* q3 -- -- -- */
        QTABLE_SET(9, 1);                               /* q3 -- -- q0 */
        QTABLE_SET(10, 2);                              /* q3 -- q1 -- */
        QTABLE_SET(11, 3);                              /* q3 -- q1 q0 */
        QTABLE_SET(12, 4);                              /* q3 q2 -- -- */
        QTABLE_SET(13, 5);                              /* q3 q2 -- q0 */
        QTABLE_SET(14, 6);                              /* q3 q2 q1 -- */
        QTABLE_SET(15, 7);                              /* q3 q2 q1 q0 */
    }
    return ctx;
}

// Assembly:
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x120(%rsp)
movq %rsi, 0x118(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
jne 0x40b42b
movl $0x820, %edi            # imm = 0x820
callq 0x4edaa0
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
je 0x40b8bf
movq 0x8(%rsp), %rax
movq 0x118(%rsp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rax)
leaq 0x94(%rsp), %rdi
addq $0x20, %rdi
movq 0x118(%rsp), %rsi
callq 0x411af0
movzbl %al, %eax
movl %eax, 0x114(%rsp)
leaq 0x94(%rsp), %rdi
leaq 0x94(%rsp), %rsi
addq $0x20, %rsi
movl 0x114(%rsp), %edx
xorl $-0x1, %edx
callq 0x40add0
leaq 0x94(%rsp), %rdi
addq $0x60, %rdi
leaq 0x94(%rsp), %rsi
leaq 0x94(%rsp), %rdx
addq $0x20, %rdx
callq 0x410f00
leaq 0x94(%rsp), %rdi
addq $0x40, %rdi
movl $0x1, %esi
callq 0x40fba0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
movl $0x1, %esi
callq 0x40fba0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x20, %rdi
movl $0x1, %esi
callq 0x40fba0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x40, %rdi
xorl %esi, %esi
callq 0x40fba0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x60, %rdi
movl $0x2, %esi
callq 0x40fba0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x80, %rdi
leaq 0x94(%rsp), %rsi
callq 0x40a7f0
movl $0x0, 0x114(%rsp)
cmpl $0x40, 0x114(%rsp)
jge 0x40b58a
leaq 0x94(%rsp), %rdi
callq 0x40a450
movl 0x114(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x114(%rsp)
jmp 0x40b560
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x100, %rdi            # imm = 0x100
leaq 0x94(%rsp), %rsi
callq 0x40a7f0
movq 0x8(%rsp), %rdx
addq $0x20, %rdx
addq $0x80, %rdx
leaq 0x14(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x40b1d0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x180, %rdi            # imm = 0x180
leaq 0x14(%rsp), %rsi
callq 0x40a7f0
leaq 0x94(%rsp), %rdi
callq 0x40a450
movl 0x114(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x114(%rsp)
cmpl $0x80, %eax
jl 0x40b5e3
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x200, %rdi            # imm = 0x200
leaq 0x94(%rsp), %rsi
callq 0x40a7f0
movq 0x8(%rsp), %rdx
addq $0x20, %rdx
addq $0x80, %rdx
leaq 0x14(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x40b1d0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x280, %rdi            # imm = 0x280
leaq 0x14(%rsp), %rsi
callq 0x40a7f0
movq 0x8(%rsp), %rdx
addq $0x20, %rdx
addq $0x100, %rdx            # imm = 0x100
leaq 0x14(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x40b1d0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x300, %rdi            # imm = 0x300
leaq 0x14(%rsp), %rsi
callq 0x40a7f0
movq 0x8(%rsp), %rdx
addq $0x20, %rdx
addq $0x180, %rdx            # imm = 0x180
leaq 0x14(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x40b1d0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x380, %rdi            # imm = 0x380
leaq 0x14(%rsp), %rsi
callq 0x40a7f0
leaq 0x94(%rsp), %rdi
callq 0x40a450
movl 0x114(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x114(%rsp)
cmpl $0xc0, %eax
jl 0x40b6d9
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x400, %rdi            # imm = 0x400
leaq 0x94(%rsp), %rsi
callq 0x40a7f0
movq 0x8(%rsp), %rdx
addq $0x20, %rdx
addq $0x80, %rdx
leaq 0x14(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x40b1d0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x480, %rdi            # imm = 0x480
leaq 0x14(%rsp), %rsi
callq 0x40a7f0
movq 0x8(%rsp), %rdx
addq $0x20, %rdx
addq $0x100, %rdx            # imm = 0x100
leaq 0x14(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x40b1d0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x500, %rdi            # imm = 0x500
leaq 0x14(%rsp), %rsi
callq 0x40a7f0
movq 0x8(%rsp), %rdx
addq $0x20, %rdx
addq $0x180, %rdx            # imm = 0x180
leaq 0x14(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x40b1d0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x580, %rdi            # imm = 0x580
leaq 0x14(%rsp), %rsi
callq 0x40a7f0
movq 0x8(%rsp), %rdx
addq $0x20, %rdx
addq $0x200, %rdx            # imm = 0x200
leaq 0x14(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x40b1d0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x600, %rdi            # imm = 0x600
leaq 0x14(%rsp), %rsi
callq 0x40a7f0
movq 0x8(%rsp), %rdx
addq $0x20, %rdx
addq $0x280, %rdx            # imm = 0x280
leaq 0x14(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x40b1d0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x680, %rdi            # imm = 0x680
leaq 0x14(%rsp), %rsi
callq 0x40a7f0
movq 0x8(%rsp), %rdx
addq $0x20, %rdx
addq $0x300, %rdx            # imm = 0x300
leaq 0x14(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x40b1d0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x700, %rdi            # imm = 0x700
leaq 0x14(%rsp), %rsi
callq 0x40a7f0
movq 0x8(%rsp), %rdx
addq $0x20, %rdx
addq $0x380, %rdx            # imm = 0x380
leaq 0x14(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x40b1d0
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
addq $0x780, %rdi            # imm = 0x780
leaq 0x14(%rsp), %rsi
callq 0x40a7f0
movq 0x8(%rsp), %rax
addq $0x128, %rsp            # imm = 0x128
retq
nopl (%rax)