// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/src/kat.c
// Function: do_kat
void do_kat(caesar_t *aead, int mlen, int adlen)
{
    int ret;
    unsigned long long clen;

    uint8_t key[80], nsec[64], osec[64], npub[64];
    // that 524304 ABYTES factor comes from Trivia. Don't ask.
    uint8_t pt[KAT_LIMIT], ad[KAT_LIMIT], ct[KAT_LIMIT + 524304];

    if (aead->name == NULL ||
        aead->abytes + sizeof(pt) > sizeof(ct) ||
        aead->keybytes > sizeof(key) || aead->nsecbytes > sizeof(nsec) ||
        aead->nsecbytes > sizeof(osec) || aead->npubbytes > sizeof(npub)) {
        fprintf(stderr, "do_kat(): invalid parameters\n");
    }

    memset(pt, 0x00, sizeof(pt));
    memset(ad, 0x00, sizeof(ad));
    memset(ct, 0x00, sizeof(ct));
    memset(key, 0x00, sizeof(key));
    memset(nsec, 0x00, sizeof(nsec));
    memset(npub, 0x00, sizeof(npub));

    detseq_fill(key, aead->keybytes);
    detseq_fill(pt, mlen);
    detseq_fill(ad, adlen);
    detseq_fill(npub, aead->npubbytes);
    detseq_fill(nsec, aead->nsecbytes);

    kat_vec(key, aead->keybytes, "key");
    kat_vec(nsec, aead->nsecbytes, "nsec");
    kat_vec(npub, aead->npubbytes, "npub");
    kat_vec(pt, mlen, "m");
    kat_vec(ad, adlen, "ad");

    ret = aead->encrypt(ct, &clen, pt, mlen,
        ad, adlen, nsec, npub, key);
    if (ret != 0) {
        printf("[%s] encrypt failed with code %d\n", aead->name, ret);
        return;
    }
    kat_vec(ct, clen, "c");
    printf("\n");
}

// Assembly:
pushq %rbx
subq $0xb0160, %rsp          # imm = 0xB0160
movq %rdi, 0xb0158(%rsp)
movl %esi, 0xb0154(%rsp)
movl %edx, 0xb0150(%rsp)
movq 0xb0158(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x31af
movq 0xb0158(%rsp), %rax
movslq 0x1c(%rax), %rax
addq $0x10000, %rax          # imm = 0x10000
cmpq $0x90010, %rax          # imm = 0x90010
ja 0x31af
movq 0xb0158(%rsp), %rax
movslq 0x10(%rax), %rax
cmpq $0x50, %rax
ja 0x31af
movq 0xb0158(%rsp), %rax
movslq 0x14(%rax), %rax
cmpq $0x40, %rax
ja 0x31af
movq 0xb0158(%rsp), %rax
movslq 0x14(%rax), %rax
cmpq $0x40, %rax
ja 0x31af
movq 0xb0158(%rsp), %rax
movslq 0x18(%rax), %rax
cmpq $0x40, %rax
jbe 0x31c7
movq 0x2e3a(%rip), %rax      # 0x5ff0
movq (%rax), %rdi
leaq 0x16e4(%rip), %rsi      # 0x48a4
movb $0x0, %al
callq 0x1100
leaq 0xa0030(%rsp), %rdi
xorl %esi, %esi
movl $0x10000, %edx          # imm = 0x10000
callq 0x10b0
leaq 0x90030(%rsp), %rdi
xorl %esi, %esi
movl $0x10000, %edx          # imm = 0x10000
callq 0x10b0
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x90010, %edx          # imm = 0x90010
callq 0x10b0
leaq 0xb00f0(%rsp), %rdi
xorl %esi, %esi
movl $0x50, %edx
callq 0x10b0
leaq 0xb00b0(%rsp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x10b0
leaq 0xb0030(%rsp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x10b0
leaq 0xb00f0(%rsp), %rdi
movq 0xb0158(%rsp), %rax
movl 0x10(%rax), %esi
callq 0x1dd0
leaq 0xa0030(%rsp), %rdi
movl 0xb0154(%rsp), %esi
callq 0x1dd0
leaq 0x90030(%rsp), %rdi
movl 0xb0150(%rsp), %esi
callq 0x1dd0
leaq 0xb0030(%rsp), %rdi
movq 0xb0158(%rsp), %rax
movl 0x18(%rax), %esi
callq 0x1dd0
leaq 0xb00b0(%rsp), %rdi
movq 0xb0158(%rsp), %rax
movl 0x14(%rax), %esi
callq 0x1dd0
leaq 0xb00f0(%rsp), %rdi
movq 0xb0158(%rsp), %rax
movl 0x10(%rax), %esi
leaq 0x1422(%rip), %rdx      # 0x46e8
callq 0x30a0
leaq 0xb00b0(%rsp), %rdi
movq 0xb0158(%rsp), %rax
movl 0x14(%rax), %esi
leaq 0x15dd(%rip), %rdx      # 0x48c2
callq 0x30a0
leaq 0xb0030(%rsp), %rdi
movq 0xb0158(%rsp), %rax
movl 0x18(%rax), %esi
leaq 0x13e8(%rip), %rdx      # 0x46ec
callq 0x30a0
leaq 0xa0030(%rsp), %rdi
movl 0xb0154(%rsp), %esi
leaq 0x16a6(%rip), %rdx      # 0x49c5
callq 0x30a0
leaq 0x90030(%rsp), %rdi
movl 0xb0150(%rsp), %esi
leaq 0x13b7(%rip), %rdx      # 0x46f1
callq 0x30a0
movq 0xb0158(%rsp), %rax
movq 0x28(%rax), %rax
leaq 0x20(%rsp), %rdi
leaq 0xa0030(%rsp), %rdx
movslq 0xb0154(%rsp), %rcx
leaq 0x90030(%rsp), %r8
movslq 0xb0150(%rsp), %r9
leaq 0xb00b0(%rsp), %rbx
leaq 0xb0030(%rsp), %r11
leaq 0xb00f0(%rsp), %r10
leaq 0xb0140(%rsp), %rsi
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
callq *%rax
movl %eax, 0xb014c(%rsp)
cmpl $0x0, 0xb014c(%rsp)
je 0x33d4
movq 0xb0158(%rsp), %rax
movq 0x8(%rax), %rsi
movl 0xb014c(%rsp), %edx
leaq 0x14fc(%rip), %rdi      # 0x48c7
movb $0x0, %al
callq 0x10a0
jmp 0x33fd
leaq 0x20(%rsp), %rdi
movq 0xb0140(%rsp), %rax
movl %eax, %esi
leaq 0x14db(%rip), %rdx      # 0x48c5
callq 0x30a0
leaq 0xe0c(%rip), %rdi       # 0x4202
movb $0x0, %al
callq 0x10a0
addq $0xb0160, %rsp          # imm = 0xB0160
popq %rbx
retq
nopw %cs:(%rax,%rax)