⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hmac_link.c

📁 非常好的dns解析软件
💻 C
📖 第 1 页 / 共 3 页
字号:
	hmacsha256_todns,	hmacsha256_fromdns,	hmacsha256_tofile,	hmacsha256_parse,	NULL, /* cleanup */};isc_result_tdst__hmacsha256_init(dst_func_t **funcp) {	REQUIRE(funcp != NULL);	if (*funcp == NULL)		*funcp = &hmacsha256_functions;	return (ISC_R_SUCCESS);}static isc_result_t hmacsha384_fromdns(dst_key_t *key, isc_buffer_t *data);typedef struct {	unsigned char key[ISC_SHA384_DIGESTLENGTH];} HMACSHA384_Key;static isc_result_thmacsha384_createctx(dst_key_t *key, dst_context_t *dctx) {	isc_hmacsha384_t *hmacsha384ctx;	HMACSHA384_Key *hkey = key->opaque;	hmacsha384ctx = isc_mem_get(dctx->mctx, sizeof(isc_hmacsha384_t));	if (hmacsha384ctx == NULL)		return (ISC_R_NOMEMORY);	isc_hmacsha384_init(hmacsha384ctx, hkey->key, ISC_SHA384_DIGESTLENGTH);	dctx->opaque = hmacsha384ctx;	return (ISC_R_SUCCESS);}static voidhmacsha384_destroyctx(dst_context_t *dctx) {	isc_hmacsha384_t *hmacsha384ctx = dctx->opaque;	if (hmacsha384ctx != NULL) {		isc_hmacsha384_invalidate(hmacsha384ctx);		isc_mem_put(dctx->mctx, hmacsha384ctx, sizeof(isc_hmacsha384_t));		dctx->opaque = NULL;	}}static isc_result_thmacsha384_adddata(dst_context_t *dctx, const isc_region_t *data) {	isc_hmacsha384_t *hmacsha384ctx = dctx->opaque;	isc_hmacsha384_update(hmacsha384ctx, data->base, data->length);	return (ISC_R_SUCCESS);}static isc_result_thmacsha384_sign(dst_context_t *dctx, isc_buffer_t *sig) {	isc_hmacsha384_t *hmacsha384ctx = dctx->opaque;	unsigned char *digest;	if (isc_buffer_availablelength(sig) < ISC_SHA384_DIGESTLENGTH)		return (ISC_R_NOSPACE);	digest = isc_buffer_used(sig);	isc_hmacsha384_sign(hmacsha384ctx, digest, ISC_SHA384_DIGESTLENGTH);	isc_buffer_add(sig, ISC_SHA384_DIGESTLENGTH);	return (ISC_R_SUCCESS);}static isc_result_thmacsha384_verify(dst_context_t *dctx, const isc_region_t *sig) {	isc_hmacsha384_t *hmacsha384ctx = dctx->opaque;	if (sig->length > ISC_SHA384_DIGESTLENGTH || sig->length == 0)		return (DST_R_VERIFYFAILURE);	if (isc_hmacsha384_verify(hmacsha384ctx, sig->base, sig->length))		return (ISC_R_SUCCESS);	else		return (DST_R_VERIFYFAILURE);}static isc_boolean_thmacsha384_compare(const dst_key_t *key1, const dst_key_t *key2) {	HMACSHA384_Key *hkey1, *hkey2;	hkey1 = (HMACSHA384_Key *)key1->opaque;	hkey2 = (HMACSHA384_Key *)key2->opaque;	if (hkey1 == NULL && hkey2 == NULL)		return (ISC_TRUE);	else if (hkey1 == NULL || hkey2 == NULL)		return (ISC_FALSE);	if (memcmp(hkey1->key, hkey2->key, ISC_SHA384_DIGESTLENGTH) == 0)		return (ISC_TRUE);	else		return (ISC_FALSE);}static isc_result_thmacsha384_generate(dst_key_t *key, int pseudorandom_ok) {	isc_buffer_t b;	isc_result_t ret;	int bytes;	unsigned char data[HMAC_LEN];	bytes = (key->key_size + 7) / 8;	if (bytes > HMAC_LEN) {		bytes = HMAC_LEN;		key->key_size = HMAC_LEN * 8;	}	memset(data, 0, HMAC_LEN);	ret = dst__entropy_getdata(data, bytes, ISC_TF(pseudorandom_ok != 0));	if (ret != ISC_R_SUCCESS)		return (ret);	isc_buffer_init(&b, data, bytes);	isc_buffer_add(&b, bytes);	ret = hmacsha384_fromdns(key, &b);	memset(data, 0, ISC_SHA384_DIGESTLENGTH);	return (ret);}static isc_boolean_thmacsha384_isprivate(const dst_key_t *key) {	UNUSED(key);	return (ISC_TRUE);}static voidhmacsha384_destroy(dst_key_t *key) {	HMACSHA384_Key *hkey = key->opaque;	memset(hkey, 0, sizeof(HMACSHA384_Key));	isc_mem_put(key->mctx, hkey, sizeof(HMACSHA384_Key));	key->opaque = NULL;}static isc_result_thmacsha384_todns(const dst_key_t *key, isc_buffer_t *data) {	HMACSHA384_Key *hkey;	unsigned int bytes;	REQUIRE(key->opaque != NULL);	hkey = (HMACSHA384_Key *) key->opaque;	bytes = (key->key_size + 7) / 8;	if (isc_buffer_availablelength(data) < bytes)		return (ISC_R_NOSPACE);	isc_buffer_putmem(data, hkey->key, bytes);	return (ISC_R_SUCCESS);}static isc_result_thmacsha384_fromdns(dst_key_t *key, isc_buffer_t *data) {	HMACSHA384_Key *hkey;	int keylen;	isc_region_t r;	isc_sha384_t sha384ctx;	isc_buffer_remainingregion(data, &r);	if (r.length == 0)		return (ISC_R_SUCCESS);	hkey = (HMACSHA384_Key *) isc_mem_get(key->mctx, sizeof(HMACSHA384_Key));	if (hkey == NULL)		return (ISC_R_NOMEMORY);	memset(hkey->key, 0, sizeof(hkey->key));	if (r.length > ISC_SHA384_DIGESTLENGTH) {		isc_sha384_init(&sha384ctx);		isc_sha384_update(&sha384ctx, r.base, r.length);		isc_sha384_final(hkey->key, &sha384ctx);		keylen = ISC_SHA384_DIGESTLENGTH;	}	else {		memcpy(hkey->key, r.base, r.length);		keylen = r.length;	}	key->key_size = keylen * 8;	key->opaque = hkey;	return (ISC_R_SUCCESS);}static isc_result_thmacsha384_tofile(const dst_key_t *key, const char *directory) {	int cnt = 0;	HMACSHA384_Key *hkey;	dst_private_t priv;	int bytes = (key->key_size + 7) / 8;	unsigned char buf[2];	if (key->opaque == NULL)		return (DST_R_NULLKEY);	hkey = (HMACSHA384_Key *) key->opaque;	priv.elements[cnt].tag = TAG_HMACSHA384_KEY;	priv.elements[cnt].length = bytes;	priv.elements[cnt++].data = hkey->key;	buf[0] = (key->key_bits >> 8) & 0xffU;	buf[1] = key->key_bits & 0xffU;	priv.elements[cnt].tag = TAG_HMACSHA384_BITS;	priv.elements[cnt].data = buf;	priv.elements[cnt++].length = 2;	priv.nelements = cnt;	return (dst__privstruct_writefile(key, &priv, directory));}static isc_result_thmacsha384_parse(dst_key_t *key, isc_lex_t *lexer) {	dst_private_t priv;	isc_result_t result, tresult;	isc_buffer_t b;	isc_mem_t *mctx = key->mctx;	unsigned int i;	/* read private key file */	result = dst__privstruct_parse(key, DST_ALG_HMACSHA384, lexer, mctx,				       &priv);	if (result != ISC_R_SUCCESS)		return (result);	key->key_bits = 0;	for (i = 0; i < priv.nelements; i++) {		switch (priv.elements[i].tag) {		case TAG_HMACSHA384_KEY:			isc_buffer_init(&b, priv.elements[i].data,				        priv.elements[i].length);			isc_buffer_add(&b, priv.elements[i].length);			tresult = hmacsha384_fromdns(key, &b);			if (tresult != ISC_R_SUCCESS)				result = tresult;			break;		case TAG_HMACSHA384_BITS:			tresult = getkeybits(key, &priv.elements[i]);			if (tresult != ISC_R_SUCCESS)				result = tresult;			break;		default:			result = DST_R_INVALIDPRIVATEKEY;			break;		}	}	dst__privstruct_free(&priv, mctx);	memset(&priv, 0, sizeof(priv));	return (result);}static dst_func_t hmacsha384_functions = {	hmacsha384_createctx,	hmacsha384_destroyctx,	hmacsha384_adddata,	hmacsha384_sign,	hmacsha384_verify,	NULL, /* computesecret */	hmacsha384_compare,	NULL, /* paramcompare */	hmacsha384_generate,	hmacsha384_isprivate,	hmacsha384_destroy,	hmacsha384_todns,	hmacsha384_fromdns,	hmacsha384_tofile,	hmacsha384_parse,	NULL, /* cleanup */};isc_result_tdst__hmacsha384_init(dst_func_t **funcp) {	REQUIRE(funcp != NULL);	if (*funcp == NULL)		*funcp = &hmacsha384_functions;	return (ISC_R_SUCCESS);}static isc_result_t hmacsha512_fromdns(dst_key_t *key, isc_buffer_t *data);typedef struct {	unsigned char key[ISC_SHA512_DIGESTLENGTH];} HMACSHA512_Key;static isc_result_thmacsha512_createctx(dst_key_t *key, dst_context_t *dctx) {	isc_hmacsha512_t *hmacsha512ctx;	HMACSHA512_Key *hkey = key->opaque;	hmacsha512ctx = isc_mem_get(dctx->mctx, sizeof(isc_hmacsha512_t));	if (hmacsha512ctx == NULL)		return (ISC_R_NOMEMORY);	isc_hmacsha512_init(hmacsha512ctx, hkey->key, ISC_SHA512_DIGESTLENGTH);	dctx->opaque = hmacsha512ctx;	return (ISC_R_SUCCESS);}static voidhmacsha512_destroyctx(dst_context_t *dctx) {	isc_hmacsha512_t *hmacsha512ctx = dctx->opaque;	if (hmacsha512ctx != NULL) {		isc_hmacsha512_invalidate(hmacsha512ctx);		isc_mem_put(dctx->mctx, hmacsha512ctx, sizeof(isc_hmacsha512_t));		dctx->opaque = NULL;	}}static isc_result_thmacsha512_adddata(dst_context_t *dctx, const isc_region_t *data) {	isc_hmacsha512_t *hmacsha512ctx = dctx->opaque;	isc_hmacsha512_update(hmacsha512ctx, data->base, data->length);	return (ISC_R_SUCCESS);}static isc_result_thmacsha512_sign(dst_context_t *dctx, isc_buffer_t *sig) {	isc_hmacsha512_t *hmacsha512ctx = dctx->opaque;	unsigned char *digest;	if (isc_buffer_availablelength(sig) < ISC_SHA512_DIGESTLENGTH)		return (ISC_R_NOSPACE);	digest = isc_buffer_used(sig);	isc_hmacsha512_sign(hmacsha512ctx, digest, ISC_SHA512_DIGESTLENGTH);	isc_buffer_add(sig, ISC_SHA512_DIGESTLENGTH);	return (ISC_R_SUCCESS);}static isc_result_thmacsha512_verify(dst_context_t *dctx, const isc_region_t *sig) {	isc_hmacsha512_t *hmacsha512ctx = dctx->opaque;	if (sig->length > ISC_SHA512_DIGESTLENGTH || sig->length == 0)		return (DST_R_VERIFYFAILURE);	if (isc_hmacsha512_verify(hmacsha512ctx, sig->base, sig->length))		return (ISC_R_SUCCESS);	else		return (DST_R_VERIFYFAILURE);}static isc_boolean_thmacsha512_compare(const dst_key_t *key1, const dst_key_t *key2) {	HMACSHA512_Key *hkey1, *hkey2;	hkey1 = (HMACSHA512_Key *)key1->opaque;	hkey2 = (HMACSHA512_Key *)key2->opaque;	if (hkey1 == NULL && hkey2 == NULL)		return (ISC_TRUE);	else if (hkey1 == NULL || hkey2 == NULL)		return (ISC_FALSE);	if (memcmp(hkey1->key, hkey2->key, ISC_SHA512_DIGESTLENGTH) == 0)		return (ISC_TRUE);	else		return (ISC_FALSE);}static isc_result_thmacsha512_generate(dst_key_t *key, int pseudorandom_ok) {	isc_buffer_t b;	isc_result_t ret;	int bytes;	unsigned char data[HMAC_LEN];	bytes = (key->key_size + 7) / 8;	if (bytes > HMAC_LEN) {		bytes = HMAC_LEN;		key->key_size = HMAC_LEN * 8;	}	memset(data, 0, HMAC_LEN);	ret = dst__entropy_getdata(data, bytes, ISC_TF(pseudorandom_ok != 0));	if (ret != ISC_R_SUCCESS)		return (ret);	isc_buffer_init(&b, data, bytes);	isc_buffer_add(&b, bytes);	ret = hmacsha512_fromdns(key, &b);	memset(data, 0, ISC_SHA512_DIGESTLENGTH);	return (ret);}static isc_boolean_thmacsha512_isprivate(const dst_key_t *key) {	UNUSED(key);	return (ISC_TRUE);}static voidhmacsha512_destroy(dst_key_t *key) {	HMACSHA512_Key *hkey = key->opaque;	memset(hkey, 0, sizeof(HMACSHA512_Key));	isc_mem_put(key->mctx, hkey, sizeof(HMACSHA512_Key));	key->opaque = NULL;}static isc_result_thmacsha512_todns(const dst_key_t *key, isc_buffer_t *data) {	HMACSHA512_Key *hkey;	unsigned int bytes;	REQUIRE(key->opaque != NULL);	hkey = (HMACSHA512_Key *) key->opaque;	bytes = (key->key_size + 7) / 8;	if (isc_buffer_availablelength(data) < bytes)		return (ISC_R_NOSPACE);	isc_buffer_putmem(data, hkey->key, bytes);	return (ISC_R_SUCCESS);}static isc_result_thmacsha512_fromdns(dst_key_t *key, isc_buffer_t *data) {	HMACSHA512_Key *hkey;	int keylen;	isc_region_t r;	isc_sha512_t sha512ctx;	isc_buffer_remainingregion(data, &r);	if (r.length == 0)		return (ISC_R_SUCCESS);	hkey = (HMACSHA512_Key *) isc_mem_get(key->mctx, sizeof(HMACSHA512_Key));	if (hkey == NULL)		return (ISC_R_NOMEMORY);	memset(hkey->key, 0, sizeof(hkey->key));	if (r.length > ISC_SHA512_DIGESTLENGTH) {		isc_sha512_init(&sha512ctx);		isc_sha512_update(&sha512ctx, r.base, r.length);		isc_sha512_final(hkey->key, &sha512ctx);		keylen = ISC_SHA512_DIGESTLENGTH;	}	else {		memcpy(hkey->key, r.base, r.length);		keylen = r.length;	}	key->key_size = keylen * 8;	key->opaque = hkey;	return (ISC_R_SUCCESS);}static isc_result_thmacsha512_tofile(const dst_key_t *key, const char *directory) {	int cnt = 0;	HMACSHA512_Key *hkey;	dst_private_t priv;	int bytes = (key->key_size + 7) / 8;	unsigned char buf[2];	if (key->opaque == NULL)		return (DST_R_NULLKEY);	hkey = (HMACSHA512_Key *) key->opaque;	priv.elements[cnt].tag = TAG_HMACSHA512_KEY;	priv.elements[cnt].length = bytes;	priv.elements[cnt++].data = hkey->key;	buf[0] = (key->key_bits >> 8) & 0xffU;	buf[1] = key->key_bits & 0xffU;	priv.elements[cnt].tag = TAG_HMACSHA512_BITS;	priv.elements[cnt].data = buf;	priv.elements[cnt++].length = 2;	priv.nelements = cnt;	return (dst__privstruct_writefile(key, &priv, directory));}static isc_result_thmacsha512_parse(dst_key_t *key, isc_lex_t *lexer) {	dst_private_t priv;	isc_result_t result, tresult;	isc_buffer_t b;	isc_mem_t *mctx = key->mctx;	unsigned int i;	/* read private key file */	result = dst__privstruct_parse(key, DST_ALG_HMACSHA512, lexer, mctx,				       &priv);	if (result != ISC_R_SUCCESS)		return (result);	key->key_bits = 0;	for (i = 0; i < priv.nelements; i++) {		switch (priv.elements[i].tag) {		case TAG_HMACSHA512_KEY:			isc_buffer_init(&b, priv.elements[i].data,				        priv.elements[i].length);			isc_buffer_add(&b, priv.elements[i].length);			tresult = hmacsha512_fromdns(key, &b);			if (tresult != ISC_R_SUCCESS)				result = tresult;			break;		case TAG_HMACSHA512_BITS:			tresult = getkeybits(key, &priv.elements[i]);			if (tresult != ISC_R_SUCCESS)				result = tresult;			break;		default:			result = DST_R_INVALIDPRIVATEKEY;			break;		}	}	dst__privstruct_free(&priv, mctx);	memset(&priv, 0, sizeof(priv));	return (result);}static dst_func_t hmacsha512_functions = {	hmacsha512_createctx,	hmacsha512_destroyctx,	hmacsha512_adddata,	hmacsha512_sign,	hmacsha512_verify,	NULL, /* computesecret */	hmacsha512_compare,	NULL, /* paramcompare */	hmacsha512_generate,	hmacsha512_isprivate,	hmacsha512_destroy,	hmacsha512_todns,	hmacsha512_fromdns,	hmacsha512_tofile,	hmacsha512_parse,	NULL, /* cleanup */};isc_result_tdst__hmacsha512_init(dst_func_t **funcp) {	REQUIRE(funcp != NULL);	if (*funcp == NULL)		*funcp = &hmacsha512_functions;	return (ISC_R_SUCCESS);}/*! \file */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -