Beispiel #1
0
	static std::tuple<bool, std::vector<uint8_t> > decrypt(
		const std::vector<uint8_t> header, 
		const std::vector<uint8_t> cipher, 
		const std::vector<uint8_t> footer,
		const std::array<uint8_t, 16>& nonce,
		const std::array<uint8_t, 16>& key) {
		std::vector<uint8_t> plain;
		plain.resize(cipher.size());

		unsigned char* p = plain.data();
		size_t pLen = plain.size();
		const unsigned char* h = header.empty() ? 0 : header.data();
		size_t hLen = header.size();
		const unsigned char* c = cipher.data();
		size_t cLen = cipher.size();
		const unsigned char* t = footer.empty() ? 0 : footer.data();
		size_t tLen = footer.size();

		std::tuple<bool, std::vector<uint8_t> > retVal;
		std::get<0>(retVal) = false;
		if (norx_aead_decrypt(p, &pLen, h, hLen, c, cLen, t, tLen, nonce.data(), key.data()) == 0) {
			plain.resize(pLen);
			std::get<1>(retVal) = plain;
			std::get<0>(retVal) = true;
		}
		return retVal;
	}
Beispiel #2
0
/*
the code for the cipher implementation goes here,
generating a plaintext m[0],m[1],...,m[*mlen-1]
and secret message number nsec[0],nsec[1],...
from a ciphertext c[0],c[1],...,c[clen-1]
and associated data ad[0],ad[1],...,ad[adlen-1]
and public message number npub[0],npub[1],...
and secret key k[0],k[1],...
*/
int crypto_aead_decrypt(
    unsigned char *m, unsigned long long *mlen,
    unsigned char *nsec,
    const unsigned char *c, unsigned long long clen,
    const unsigned char *ad, unsigned long long adlen,
    const unsigned char *npub,
    const unsigned char *k
    )
{
    size_t outlen = 0;
    int result = norx_aead_decrypt(m, &outlen, ad, adlen, c, clen, NULL, 0, npub, k);
    *mlen = outlen;
    (void)nsec; /* avoid warning */
    return result;
}