#!/bin/sh

test_description="Check passphrase-encrypted key decryption"
. $SHARNESS_TEST_SRCDIR/sharness.sh

cmkeytool -algo sntrup761-x25519 -ku kem -sub A=KEY 5>enc.pub 9>enc.prv
dd if=/dev/urandom of=enc.data bs=12K count=1 2>/dev/null
export CM_PASSPHRASE=$(dd if=/dev/urandom bs=32 count=1 2>/dev/null | xxd -p)
balloonparams="-balloon-s 123 -balloon-t 2"
test_expect_success "key encrypting" "
    cmenctool -p -embed $balloonparams <enc.prv >enc.prv.enc"
test_expect_success "data encrypting" "
    cmenctool 4<enc.pub <enc.data >enc.enc"
test_expect_success "decrypting" "
    cmenctool -d 8<enc.prv.enc <enc.enc >enc.data.got"
test_expect_success "comparing" "test_cmp enc.data enc.data.got"

test_done
