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

📄 auth_test.c

📁 mobile ip 在linux下的一种实现
💻 C
字号:
/* $Id: auth_test.c,v 1.2 2001/08/04 20:46:52 jm Exp $ * Test authentication routines * * Dynamic hierarchial IP tunnel * Copyright (C) 2001, Jouni Malinen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. See README and COPYING for * more details. */#include <stdlib.h>#include <stdio.h>#include "debug.h"#include "auth.h"#include "message.h"void test_auth(int alg, unsigned char *secret, unsigned int secret_len){	unsigned char buf[1024];	int i;	struct msg_auth *auth;	struct vendor_msg_auth *vauth;	struct generalized_auth_ext *gauth;	printf("Algorithm %i\n", alg);	for (i = 0; i < 1024; i++)		buf[i] = i % 256;	auth = (struct msg_auth *) &buf[512];	auth_add(alg, secret, secret_len, buf, auth, 123, htons(1234));	if (auth_check(alg, secret, secret_len, buf, auth) == 0 ||	    auth_check(alg, "wrong", 5, buf, auth) != 0)		printf("   auth_add/auth_check did not match!\n");	for (i = 0; i < 512; i++)		if (buf[i] != i % 256)			printf("   buf[%i] changed: %i -> %i\n",			       i, i % 256, buf[i]);	for (i = 0; i < 1024; i++)		buf[i] = i % 256;	vauth = (struct vendor_msg_auth *) &buf[512];	auth_add_vendor(alg, secret, secret_len, buf, vauth, 123, htons(1234));	if (auth_check_vendor(alg, secret, secret_len, buf, vauth) == 0 ||	    auth_check_vendor(alg, "wrong", 5, buf, vauth) != 0)		printf("   auth_add_vendor/auth_check_vendor did not match!"		       "\n");	for (i = 0; i < 512; i++)		if (buf[i] != i % 256)			printf("   buf[%i] changed: %i -> %i\n",			       i, i % 256, buf[i]);	for (i = 0; i < 1024; i++)		buf[i] = i % 256;	gauth = (struct generalized_auth_ext *) &buf[512];	auth_add_gen(alg, secret, secret_len, buf, "challenge", 9, gauth, 123,		     htons(1234));	if (auth_check_gen(alg, secret, secret_len, buf, gauth) == 0 ||	    auth_check_gen(alg, "wrong", 5, buf, gauth) != 0)		printf("   auth_add_gen/auth_check_gen did not match!"		       "\n");	for (i = 0; i < 512; i++)		if (buf[i] != i % 256)			printf("   buf[%i] changed: %i -> %i\n",			       i, i % 256, buf[i]);}extern int opt_debug;int main(int argc, char *argv[]){	opt_debug = 1;	test_auth(AUTH_ALG_MD5, "foobar", 6);	test_auth(AUTH_ALG_MD5_RFC2002, "foobar", 6);	test_auth(AUTH_ALG_MD5_PREFIX_SUFFIX, "foobar", 6);	test_auth(AUTH_ALG_HMAC_MD5, "foobar", 6);	test_auth(AUTH_ALG_SHA1, "foobar", 6);	test_auth(AUTH_ALG_HMAC_SHA1, "foobar", 6);	return 0;}

⌨️ 快捷键说明

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