Пример #1
0
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
	)
{
	uint8 loctag[BLOCK];
	block TA = _mm_setzero_si128(), TE;

	*mlen = clen - CRYPTO_ABYTES;
	Setup(k);
#if (ADP==Para)
	if ((uint32)adlen > 0){
		TA = AFunc(ad, (uint32)adlen);
	}
	TE = DFunc(npub, CRYPTO_NPUBBYTES, c,
		(uint32)clen - CRYPTO_ABYTES, CRYPTO_ABYTES, m);
	TE = _mm_xor_si128(TE, TA);
#else 
	if ((uint32)adlen > 0){
		TA = AFuncS(ad, (uint32)adlen);
	}
	TE = DFunc(npub, CRYPTO_NPUBBYTES, TA, c,
		(uint32)clen - CRYPTO_ABYTES, CRYPTO_ABYTES, m);
#endif
	memcpy(loctag, (uint8*)&TE, CRYPTO_ABYTES);
	if (memcmp(loctag, c + (uint32)*mlen, CRYPTO_ABYTES) != 0){//non-constant-time compare
		return TAG_UNMATCH; //-1
	}
	return TAG_MATCH; //0
}
Пример #2
0
	return 1;
}

const StdlibRegister _globalFuncs[] =
{
	_DListItem(_new),
	_DListItem(_fromArray),
	_DListEnd
};

// =====================================================================================================================
// Methods

const StdlibRegisterInfo _toString_info =
{
	Docstr(DFunc("toString")
	R"(\returns a string representation of this memblock in the form \tt{"memblock[contents]"}.

	For example, \tt{memblock.new(3, 10).toString()} would give the string \tt{"memblock[10, 10, 10]"}.

	If the memblock is more than 128 bytes, the contents will be truncated with an ellipsis.)"),

	"toString", 0
};

word_t _toString(CrocThread* t)
{
	auto data = checkMemblockParam(t, 0)->data;

	CrocStrBuffer b;
	croc_ex_buffer_init(t, &b);