Example #1
0
OM_uint32 _gssapi_unwrap_arcfour(OM_uint32 *minor_status,
				 const gsskrb5_ctx context_handle,
				 krb5_context context,
				 const gss_buffer_t input_message_buffer,
				 gss_buffer_t output_message_buffer,
				 int *conf_state,
				 gss_qop_t *qop_state,
				 krb5_keyblock *key)
{
    u_char Klocaldata[16];
    krb5_keyblock Klocal;
    krb5_error_code ret;
    uint32_t seq_number;
    size_t datalen;
    OM_uint32 omret;
    u_char k6_data[16], SND_SEQ[8], Confounder[8];
    u_char cksum_data[8];
    u_char *p, *p0;
    int cmp;
    int conf_flag;
    size_t padlen = 0, len;

    if (conf_state)
	*conf_state = 0;
    if (qop_state)
	*qop_state = 0;

    p0 = input_message_buffer->value;

    if (IS_DCE_STYLE(context_handle)) {
	len = GSS_ARCFOUR_WRAP_TOKEN_SIZE +
	    GSS_ARCFOUR_WRAP_TOKEN_DCE_DER_HEADER_SIZE;
	if (input_message_buffer->length < len)
	    return GSS_S_BAD_MECH;
    } else {
	len = input_message_buffer->length;
    }

    omret = _gssapi_verify_mech_header(&p0,
				       len,
				       GSS_KRB5_MECHANISM);
    if (omret)
	return omret;

    /* length of mech header */
    len = (p0 - (u_char *)input_message_buffer->value) +
	GSS_ARCFOUR_WRAP_TOKEN_SIZE;

    if (len > input_message_buffer->length)
	return GSS_S_BAD_MECH;

    /* length of data */
    datalen = input_message_buffer->length - len;

    p = p0;

    if (memcmp(p, "\x02\x01", 2) != 0)
	return GSS_S_BAD_SIG;
    p += 2;
    if (memcmp(p, "\x11\x00", 2) != 0) /* SGN_ALG = HMAC MD5 ARCFOUR */
	return GSS_S_BAD_SIG;
    p += 2;

    if (memcmp (p, "\x10\x00", 2) == 0)
	conf_flag = 1;
    else if (memcmp (p, "\xff\xff", 2) == 0)
	conf_flag = 0;
    else
	return GSS_S_BAD_SIG;

    p += 2;
    if (memcmp (p, "\xff\xff", 2) != 0)
	return GSS_S_BAD_MIC;
    p = NULL;

    ret = arcfour_mic_key(context, key,
			  p0 + 16, 8, /* SGN_CKSUM */
			  k6_data, sizeof(k6_data));
    if (ret) {
	*minor_status = ret;
	return GSS_S_FAILURE;
    }

    {
	RC4_KEY rc4_key;
	
	RC4_set_key (&rc4_key, sizeof(k6_data), k6_data);
	RC4 (&rc4_key, 8, p0 + 8, SND_SEQ); /* SND_SEQ */
	memset(&rc4_key, 0, sizeof(rc4_key));
	memset(k6_data, 0, sizeof(k6_data));
    }

    _gsskrb5_decode_be_om_uint32(SND_SEQ, &seq_number);

    if (context_handle->more_flags & LOCAL)
	cmp = memcmp(&SND_SEQ[4], "\xff\xff\xff\xff", 4);
    else
	cmp = memcmp(&SND_SEQ[4], "\x00\x00\x00\x00", 4);

    if (cmp != 0) {
	*minor_status = 0;
	return GSS_S_BAD_MIC;
    }

    {
	int i;

	Klocal.keytype = key->keytype;
	Klocal.keyvalue.data = Klocaldata;
	Klocal.keyvalue.length = sizeof(Klocaldata);

	for (i = 0; i < 16; i++)
	    Klocaldata[i] = ((u_char *)key->keyvalue.data)[i] ^ 0xF0;
    }
    ret = arcfour_mic_key(context, &Klocal,
			  SND_SEQ, 4,
			  k6_data, sizeof(k6_data));
    memset(Klocaldata, 0, sizeof(Klocaldata));
    if (ret) {
	*minor_status = ret;
	return GSS_S_FAILURE;
    }

    output_message_buffer->value = malloc(datalen);
    if (output_message_buffer->value == NULL) {
	*minor_status = ENOMEM;
	return GSS_S_FAILURE;
    }
    output_message_buffer->length = datalen;

    if(conf_flag) {
	RC4_KEY rc4_key;

	RC4_set_key (&rc4_key, sizeof(k6_data), k6_data);
	RC4 (&rc4_key, 8, p0 + 24, Confounder); /* Confounder */
	RC4 (&rc4_key, datalen, p0 + GSS_ARCFOUR_WRAP_TOKEN_SIZE,
	     output_message_buffer->value);
	memset(&rc4_key, 0, sizeof(rc4_key));
    } else {
	memcpy(Confounder, p0 + 24, 8); /* Confounder */
	memcpy(output_message_buffer->value,
	       p0 + GSS_ARCFOUR_WRAP_TOKEN_SIZE,
	       datalen);
    }
    memset(k6_data, 0, sizeof(k6_data));

    if (!IS_DCE_STYLE(context_handle)) {
	ret = _gssapi_verify_pad(output_message_buffer, datalen, &padlen);
	if (ret) {
	    _gsskrb5_release_buffer(minor_status, output_message_buffer);
	    *minor_status = 0;
	    return ret;
	}
	output_message_buffer->length -= padlen;
    }

    ret = arcfour_mic_cksum(context,
			    key, KRB5_KU_USAGE_SEAL,
			    cksum_data, sizeof(cksum_data),
			    p0, 8,
			    Confounder, sizeof(Confounder),
			    output_message_buffer->value,
			    output_message_buffer->length + padlen);
    if (ret) {
	_gsskrb5_release_buffer(minor_status, output_message_buffer);
	*minor_status = ret;
	return GSS_S_FAILURE;
    }

    cmp = memcmp(cksum_data, p0 + 16, 8); /* SGN_CKSUM */
    if (cmp) {
	_gsskrb5_release_buffer(minor_status, output_message_buffer);
	*minor_status = 0;
	return GSS_S_BAD_MIC;
    }

    HEIMDAL_MUTEX_lock(&context_handle->ctx_id_mutex);
    omret = _gssapi_msg_order_check(context_handle->order, seq_number);
    HEIMDAL_MUTEX_unlock(&context_handle->ctx_id_mutex);
    if (omret)
	return omret;

    if (conf_state)
	*conf_state = conf_flag;

    *minor_status = 0;
    return GSS_S_COMPLETE;
}
Example #2
0
OM_uint32
_gssapi_verify_mic_arcfour(OM_uint32 * minor_status,
			   const gsskrb5_ctx context_handle,
			   krb5_context context,
			   const gss_buffer_t message_buffer,
			   const gss_buffer_t token_buffer,
			   gss_qop_t * qop_state,
			   krb5_keyblock *key,
			   char *type)
{
    krb5_error_code ret;
    uint32_t seq_number;
    OM_uint32 omret;
    u_char SND_SEQ[8], cksum_data[8], *p;
    char k6_data[16];
    int cmp;

    if (qop_state)
	*qop_state = 0;

    p = token_buffer->value;
    omret = _gsskrb5_verify_header (&p,
				       token_buffer->length,
				       (u_char *)type,
				       GSS_KRB5_MECHANISM);
    if (omret)
	return omret;

    if (memcmp(p, "\x11\x00", 2) != 0) /* SGN_ALG = HMAC MD5 ARCFOUR */
	return GSS_S_BAD_SIG;
    p += 2;
    if (memcmp (p, "\xff\xff\xff\xff", 4) != 0)
	return GSS_S_BAD_MIC;
    p += 4;

    ret = arcfour_mic_cksum(context,
			    key, KRB5_KU_USAGE_SIGN,
			    cksum_data, sizeof(cksum_data),
			    p - 8, 8,
			    message_buffer->value, message_buffer->length,
			    NULL, 0);
    if (ret) {
	*minor_status = ret;
	return GSS_S_FAILURE;
    }

    ret = arcfour_mic_key(context, key,
			  cksum_data, sizeof(cksum_data),
			  k6_data, sizeof(k6_data));
    if (ret) {
	*minor_status = ret;
	return GSS_S_FAILURE;
    }

    cmp = memcmp(cksum_data, p + 8, 8);
    if (cmp) {
	*minor_status = 0;
	return GSS_S_BAD_MIC;
    }

    {
	RC4_KEY rc4_key;
	
	RC4_set_key (&rc4_key, sizeof(k6_data), (void*)k6_data);
	RC4 (&rc4_key, 8, p, SND_SEQ);
	
	memset(&rc4_key, 0, sizeof(rc4_key));
	memset(k6_data, 0, sizeof(k6_data));
    }

    _gsskrb5_decode_be_om_uint32(SND_SEQ, &seq_number);

    if (context_handle->more_flags & LOCAL)
	cmp = memcmp(&SND_SEQ[4], "\xff\xff\xff\xff", 4);
    else
	cmp = memcmp(&SND_SEQ[4], "\x00\x00\x00\x00", 4);

    memset(SND_SEQ, 0, sizeof(SND_SEQ));
    if (cmp != 0) {
	*minor_status = 0;
	return GSS_S_BAD_MIC;
    }

    HEIMDAL_MUTEX_lock(&context_handle->ctx_id_mutex);
    omret = _gssapi_msg_order_check(context_handle->order, seq_number);
    HEIMDAL_MUTEX_unlock(&context_handle->ctx_id_mutex);
    if (omret)
	return omret;

    *minor_status = 0;
    return GSS_S_COMPLETE;
}
Example #3
0
OM_uint32
_gssapi_wrap_arcfour(OM_uint32 * minor_status,
		     const gsskrb5_ctx context_handle,
		     krb5_context context,
		     int conf_req_flag,
		     gss_qop_t qop_req,
		     const gss_buffer_t input_message_buffer,
		     int * conf_state,
		     gss_buffer_t output_message_buffer,
		     krb5_keyblock *key)
{
    u_char Klocaldata[16], k6_data[16], *p, *p0;
    size_t len, total_len, datalen;
    krb5_keyblock Klocal;
    krb5_error_code ret;
    int32_t seq_number;

    if (conf_state)
	*conf_state = 0;

    datalen = input_message_buffer->length;

    if (IS_DCE_STYLE(context_handle)) {
	len = GSS_ARCFOUR_WRAP_TOKEN_SIZE;
	_gssapi_encap_length(len, &len, &total_len, GSS_KRB5_MECHANISM);
	total_len += datalen;
    } else {
	datalen += 1; /* padding */
	len = datalen + GSS_ARCFOUR_WRAP_TOKEN_SIZE;
	_gssapi_encap_length(len, &len, &total_len, GSS_KRB5_MECHANISM);
    }

    output_message_buffer->length = total_len;
    output_message_buffer->value  = malloc (total_len);
    if (output_message_buffer->value == NULL) {
	*minor_status = ENOMEM;
	return GSS_S_FAILURE;
    }

    p0 = _gssapi_make_mech_header(output_message_buffer->value,
				  len,
				  GSS_KRB5_MECHANISM);
    p = p0;

    *p++ = 0x02; /* TOK_ID */
    *p++ = 0x01;
    *p++ = 0x11; /* SGN_ALG */
    *p++ = 0x00;
    if (conf_req_flag) {
	*p++ = 0x10; /* SEAL_ALG */
	*p++ = 0x00;
    } else {
	*p++ = 0xff; /* SEAL_ALG */
	*p++ = 0xff;
    }
    *p++ = 0xff; /* Filler */
    *p++ = 0xff;

    p = NULL;

    HEIMDAL_MUTEX_lock(&context_handle->ctx_id_mutex);
    krb5_auth_con_getlocalseqnumber (context,
				     context_handle->auth_context,
				     &seq_number);

    _gsskrb5_encode_be_om_uint32(seq_number, p0 + 8);

    krb5_auth_con_setlocalseqnumber (context,
				     context_handle->auth_context,
				     ++seq_number);
    HEIMDAL_MUTEX_unlock(&context_handle->ctx_id_mutex);

    memset (p0 + 8 + 4,
	    (context_handle->more_flags & LOCAL) ? 0 : 0xff,
	    4);

    krb5_generate_random_block(p0 + 24, 8); /* fill in Confounder */

    /* p points to data */
    p = p0 + GSS_ARCFOUR_WRAP_TOKEN_SIZE;
    memcpy(p, input_message_buffer->value, input_message_buffer->length);

    if (!IS_DCE_STYLE(context_handle))
	p[input_message_buffer->length] = 1; /* padding */

    ret = arcfour_mic_cksum(context,
			    key, KRB5_KU_USAGE_SEAL,
			    p0 + 16, 8, /* SGN_CKSUM */
			    p0, 8, /* TOK_ID, SGN_ALG, SEAL_ALG, Filler */
			    p0 + 24, 8, /* Confounder */
			    p0 + GSS_ARCFOUR_WRAP_TOKEN_SIZE,
			    datalen);
    if (ret) {
	*minor_status = ret;
	_gsskrb5_release_buffer(minor_status, output_message_buffer);
	return GSS_S_FAILURE;
    }

    {
	int i;

	Klocal.keytype = key->keytype;
	Klocal.keyvalue.data = Klocaldata;
	Klocal.keyvalue.length = sizeof(Klocaldata);

	for (i = 0; i < 16; i++)
	    Klocaldata[i] = ((u_char *)key->keyvalue.data)[i] ^ 0xF0;
    }
    ret = arcfour_mic_key(context, &Klocal,
			  p0 + 8, 4, /* SND_SEQ */
			  k6_data, sizeof(k6_data));
    memset(Klocaldata, 0, sizeof(Klocaldata));
    if (ret) {
	_gsskrb5_release_buffer(minor_status, output_message_buffer);
	*minor_status = ret;
	return GSS_S_FAILURE;
    }


    if(conf_req_flag) {
	RC4_KEY rc4_key;

	RC4_set_key (&rc4_key, sizeof(k6_data), (void *)k6_data);
	/* XXX ? */
	RC4 (&rc4_key, 8 + datalen, p0 + 24, p0 + 24); /* Confounder + data */
	memset(&rc4_key, 0, sizeof(rc4_key));
    }
    memset(k6_data, 0, sizeof(k6_data));

    ret = arcfour_mic_key(context, key,
			  p0 + 16, 8, /* SGN_CKSUM */
			  k6_data, sizeof(k6_data));
    if (ret) {
	_gsskrb5_release_buffer(minor_status, output_message_buffer);
	*minor_status = ret;
	return GSS_S_FAILURE;
    }

    {
	RC4_KEY rc4_key;
	
	RC4_set_key (&rc4_key, sizeof(k6_data), k6_data);
	RC4 (&rc4_key, 8, p0 + 8, p0 + 8); /* SND_SEQ */
	memset(&rc4_key, 0, sizeof(rc4_key));
	memset(k6_data, 0, sizeof(k6_data));
    }

    if (conf_state)
	*conf_state = conf_req_flag;

    *minor_status = 0;
    return GSS_S_COMPLETE;
}
Example #4
0
int main(int argc, char *argv[])
	{
	int i,err=0;
	int j;
	unsigned char *p;
	RC4_KEY key;
	unsigned char buf[512],obuf[512];

	for (i=0; i<512; i++) buf[i]=0x01;

	for (i=0; i<6; i++)
		{
		RC4_set_key(&key,keys[i][0],&(keys[i][1]));
		memset(obuf,0x00,sizeof(obuf));
		RC4(&key,data_len[i],&(data[i][0]),obuf);
		if (memcmp(obuf,output[i],data_len[i]+1) != 0)
			{
			printf("error calculating RC4\n");
			printf("output:");
			for (j=0; j<data_len[i]+1; j++)
				printf(" %02x",obuf[j]);
			printf("\n");
			printf("expect:");
			p= &(output[i][0]);
			for (j=0; j<data_len[i]+1; j++)
				printf(" %02x",*(p++));
			printf("\n");
			err++;
			}
		else
			printf("test %d ok\n",i);
		}
	printf("test end processing ");
	for (i=0; i<data_len[3]; i++)
		{
		RC4_set_key(&key,keys[3][0],&(keys[3][1]));
		memset(obuf,0x00,sizeof(obuf));
		RC4(&key,i,&(data[3][0]),obuf);
		if ((memcmp(obuf,output[3],i) != 0) || (obuf[i] != 0))
			{
			printf("error in RC4 length processing\n");
			printf("output:");
			for (j=0; j<i+1; j++)
				printf(" %02x",obuf[j]);
			printf("\n");
			printf("expect:");
			p= &(output[3][0]);
			for (j=0; j<i; j++)
				printf(" %02x",*(p++));
			printf(" 00\n");
			err++;
			}
		else
			{
			printf(".");
			fflush(stdout);
			}
		}
	printf("done\n");
	printf("test multi-call ");
	for (i=0; i<data_len[3]; i++)
		{
		RC4_set_key(&key,keys[3][0],&(keys[3][1]));
		memset(obuf,0x00,sizeof(obuf));
		RC4(&key,i,&(data[3][0]),obuf);
		RC4(&key,data_len[3]-i,&(data[3][i]),&(obuf[i]));
		if (memcmp(obuf,output[3],data_len[3]+1) != 0)
			{
			printf("error in RC4 multi-call processing\n");
			printf("output:");
			for (j=0; j<data_len[3]+1; j++)
				printf(" %02x",obuf[j]);
			printf("\n");
			printf("expect:");
			p= &(output[3][0]);
			for (j=0; j<data_len[3]+1; j++)
				printf(" %02x",*(p++));
			err++;
			}
		else
			{
			printf(".");
			fflush(stdout);
			}
		}
	printf("done\n");
	EXIT(err);
	return(0);
	}
Example #5
0
OM_uint32
_gssapi_get_mic_arcfour(OM_uint32 * minor_status,
			const gsskrb5_ctx context_handle,
			krb5_context context,
			gss_qop_t qop_req,
			const gss_buffer_t message_buffer,
			gss_buffer_t message_token,
			krb5_keyblock *key)
{
    krb5_error_code ret;
    int32_t seq_number;
    size_t len, total_len;
    u_char k6_data[16], *p0, *p;
    RC4_KEY rc4_key;

    _gsskrb5_encap_length (22, &len, &total_len, GSS_KRB5_MECHANISM);

    message_token->length = total_len;
    message_token->value  = malloc (total_len);
    if (message_token->value == NULL) {
	*minor_status = ENOMEM;
	return GSS_S_FAILURE;
    }

    p0 = _gssapi_make_mech_header(message_token->value,
				  len,
				  GSS_KRB5_MECHANISM);
    p = p0;

    *p++ = 0x01; /* TOK_ID */
    *p++ = 0x01;
    *p++ = 0x11; /* SGN_ALG */
    *p++ = 0x00;
    *p++ = 0xff; /* Filler */
    *p++ = 0xff;
    *p++ = 0xff;
    *p++ = 0xff;

    p = NULL;

    ret = arcfour_mic_cksum(context,
			    key, KRB5_KU_USAGE_SIGN,
			    p0 + 16, 8,  /* SGN_CKSUM */
			    p0, 8, /* TOK_ID, SGN_ALG, Filer */
			    message_buffer->value, message_buffer->length,
			    NULL, 0);
    if (ret) {
	_gsskrb5_release_buffer(minor_status, message_token);
	*minor_status = ret;
	return GSS_S_FAILURE;
    }

    ret = arcfour_mic_key(context, key,
			  p0 + 16, 8, /* SGN_CKSUM */
			  k6_data, sizeof(k6_data));
    if (ret) {
	_gsskrb5_release_buffer(minor_status, message_token);
	*minor_status = ret;
	return GSS_S_FAILURE;
    }

    HEIMDAL_MUTEX_lock(&context_handle->ctx_id_mutex);
    krb5_auth_con_getlocalseqnumber (context,
				     context_handle->auth_context,
				     &seq_number);
    p = p0 + 8; /* SND_SEQ */
    _gsskrb5_encode_be_om_uint32(seq_number, p);

    krb5_auth_con_setlocalseqnumber (context,
				     context_handle->auth_context,
				     ++seq_number);
    HEIMDAL_MUTEX_unlock(&context_handle->ctx_id_mutex);

    memset (p + 4, (context_handle->more_flags & LOCAL) ? 0 : 0xff, 4);

    RC4_set_key (&rc4_key, sizeof(k6_data), k6_data);
    RC4 (&rc4_key, 8, p, p);
	
    memset(&rc4_key, 0, sizeof(rc4_key));
    memset(k6_data, 0, sizeof(k6_data));

    *minor_status = 0;
    return GSS_S_COMPLETE;
}
Example #6
0
static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
		      const unsigned char *in, unsigned int inl)
	{
	RC4(&data(ctx)->ks,inl,in,out);
	return 1;
	}
Example #7
0
void crypto_rc4(CryptoRc4 rc4, uint32 length, const uint8* in_data, uint8* out_data)
{
	RC4(&rc4->rc4_key, length, in_data, out_data);
}
Example #8
0
BOOL CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	OPENFILENAME ofn;
	POINT pt;
	RECT rect;
	switch(uMsg){
	case WM_INITDIALOG:
		InitCommonControls();
		hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_MAIN));
		SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIcon);
		CheckDlgButton(hDlg, IDC_BACKUP, BST_CHECKED);
		SendMessage(GetDlgItem(hDlg, IDC_FILE), EM_SETREADONLY, (WPARAM)TRUE, (LPARAM)0);
		hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_EXE));
		SendMessage(GetDlgItem(hDlg, IDC_ICONIMG), STM_SETICON, (WPARAM)hIcon, (LPARAM)0);
		EnableWindow(GetDlgItem(hDlg, IDC_BUILD), FALSE);
		SetWindowPos(hDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
		break;
	case WM_CLOSE:
		EndDialog(hDlg, 0);
		break;
	case WM_PAINT:
		SendMessage(GetDlgItem(hDlg, IDC_ICONIMG), STM_SETICON, (WPARAM)hIcon, (LPARAM)0);
		break;
	case WM_DROPFILES:
		HDROP hDrop;
		hDrop = HDROP(wParam);
		DragQueryFile(hDrop, 0, szEFileName, sizeof(szEFileName));
		DragFinish(hDrop);
		if(LoadPE(szEFileName) == FALSE)
		{
			MessageBox(hDlg, "Could not load file!", "Cryptic", MB_ICONERROR);
			return TRUE;
		}
		SetDlgItemText(hDlg, IDC_FILE, szEFileName);
		EnableWindow(GetDlgItem(hDlg, IDC_BUILD), TRUE);
		break;
	case WM_MOUSEMOVE:
		GetCursorPos(&pt);
		GetWindowRect(GetDlgItem(hDlg, IDC_ICONIMG), &rect);
		if(PtInRect(&rect, pt))
		{
			SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(32649)));
		}
		else
		{
			SetCursor(LoadCursor(NULL, IDC_ARROW));
		}
		break;
	case WM_LBUTTONDOWN:
		GetCursorPos(&pt);
		GetWindowRect(GetDlgItem(hDlg, IDC_ICONIMG), &rect);
		if(PtInRect(&rect, pt))
		{
			SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(32649)));
			memset(&ofn, 0, sizeof(ofn));
			szIFileName[0] = '\0';
			ofn.lStructSize = sizeof(OPENFILENAME);
			ofn.hwndOwner = hDlg;
			ofn.lpstrFilter = "Icon Files (*.ico)\0*.ico\0\0";
			ofn.lpstrFile = szIFileName;
			ofn.nMaxFile = MAX_PATH;
			ofn.Flags = OFN_PATHMUSTEXIST;
			if(GetOpenFileName(&ofn))
			{
				hIcon = ExtractIcon(hInst, szIFileName, 0);
				SendMessage(GetDlgItem(hDlg, IDC_ICONIMG), STM_SETICON, (WPARAM)hIcon, (LPARAM)0);
			}
		}
		break;
	case WM_RBUTTONDOWN:
		GetCursorPos(&pt);
		GetWindowRect(GetDlgItem(hDlg, IDC_ICONIMG), &rect);
		if(PtInRect(&rect, pt))
		{
			SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(32649)));
		}
		break;
	case WM_COMMAND:
		switch LOWORD(wParam){
		case IDC_BROWSE:
			memset(&ofn, 0, sizeof(ofn));
			szEFileName[0] = '\0';
			ofn.lStructSize = sizeof(OPENFILENAME);
			ofn.hwndOwner = hDlg;
			ofn.lpstrFilter = "Executable Files (*.exe)\0*.exe\0\0";
			ofn.lpstrFile = szEFileName;
			ofn.nMaxFile = MAX_PATH;
			ofn.Flags = OFN_PATHMUSTEXIST;
			if(GetOpenFileName(&ofn))
			{
				if(LoadPE(szEFileName) == FALSE)
				{
					MessageBox(hDlg, "Could not load file!", "Cryptic", MB_ICONERROR);
					return TRUE;
				}
				SetDlgItemText(hDlg, IDC_FILE, szEFileName);
				EnableWindow(GetDlgItem(hDlg, IDC_BUILD), TRUE);
			}
			break;
		case IDC_BUILD:
			EnableControls(hDlg, FALSE);
			HRSRC hRsrc;
			hRsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_STUB), "STUB");
			if(hRsrc == NULL)
			{
				MessageBox(hDlg, "Could not find resource!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			DWORD dwRsrcSize;
			dwRsrcSize = SizeofResource(NULL, hRsrc);
			HGLOBAL hGlob;
			hGlob = LoadResource(NULL, hRsrc);
			if(hGlob == NULL)
			{
				MessageBox(hDlg, "Could not load resource!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			LPBYTE lpBuffer;
			lpBuffer = (LPBYTE)LockResource(hGlob);
			if(lpBuffer == NULL)
			{
				MessageBox(hDlg, "Could not lock resource!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			GetDlgItemText(hDlg, IDC_FILE, szEFileName, MAX_PATH);
			if(IsDlgButtonChecked(hDlg, IDC_BACKUP) == BST_CHECKED)
			{
				CHAR szBFileName[MAX_PATH];
				GetDlgItemText(hDlg, IDC_FILE, szBFileName, MAX_PATH);
				strcat(szBFileName, ".bak");
				if(CopyFile(szEFileName, szBFileName, FALSE) == 0)
				{
					free(lpBuffer);
					MessageBox(hDlg, "Could not copy file!", "Cryptic", MB_ICONERROR);
					EnableControls(hDlg, TRUE);
					return TRUE;
				}
			}
			BYTE lpKey[14];
			srand(time(NULL));
			int i;
			for(i = 0; i < 15; i++)
			{
				lpKey[i] = BYTE(rand() % 255 + 1);
			}
			HANDLE hFile;
			hFile = CreateFile(szEFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
			if(hFile == INVALID_HANDLE_VALUE)
			{
				free(lpBuffer);
				MessageBox(hDlg, "Could not create file!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			DWORD dwBytesWritten;
			if(WriteFile(hFile, lpBuffer, dwRsrcSize, &dwBytesWritten, NULL) == 0)
			{
				CloseHandle(hFile);
				free(lpBuffer);
				MessageBox(hDlg, "Could not write to file!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			CloseHandle(hFile);
			free(lpBuffer);
			if(IsDlgButtonChecked(hDlg, IDC_ADDICON) == BST_CHECKED)
			{
				if(AddIcon(szIFileName, szEFileName) == FALSE)
				{
					MessageBox(hDlg, "Could add icon!", "Cryptic", MB_ICONERROR);
					EnableControls(hDlg, TRUE);
					return TRUE;
				}
			}
			HANDLE hUpdate;
			hUpdate = BeginUpdateResource(szEFileName, FALSE);
			if(hUpdate == NULL)
			{
				MessageBox(hDlg, "Could add resource!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			if(UpdateResource(hUpdate, RT_RCDATA, MAKEINTRESOURCE(150), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), RC4(lpFileBuffer, lpKey, dwFileSize, 15), dwFileSize) == FALSE)
			{
				MessageBox(hDlg, "Could add resource!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			if(UpdateResource(hUpdate, RT_RCDATA, MAKEINTRESOURCE(151), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), &lpKey[0], 15) == FALSE)
			{
				MessageBox(hDlg, "Could add resource!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			if(EndUpdateResource(hUpdate, FALSE) == FALSE)
			{
				MessageBox(hDlg, "Could add resource!", "Cryptic", MB_ICONERROR);
				EnableControls(hDlg, TRUE);
				return TRUE;
			}
			RC4(lpFileBuffer, lpKey, dwFileSize, 15);
			pish = (PIMAGE_SECTION_HEADER)&lpFileBuffer[pidh->e_lfanew + sizeof(IMAGE_NT_HEADERS) + sizeof(IMAGE_SECTION_HEADER) * (pinh->FileHeader.NumberOfSections - 1)];
			if(dwFileSize > (pish->PointerToRawData + pish->SizeOfRawData))
			{
				MessageBox(hDlg, "EOF data found!", "Cryptic", MB_OK);
				hFile = CreateFile(szEFileName, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
				if(hFile == INVALID_HANDLE_VALUE)
				{
					MessageBox(hDlg, "Could not open file!", "Cryptic", MB_ICONERROR);
					EnableControls(hDlg, TRUE);
					return TRUE;
				}
				SetFilePointer(hFile, 0, NULL, FILE_END);
				if(WriteFile(hFile, &lpFileBuffer[pish->PointerToRawData + pish->SizeOfRawData + 1], dwFileSize - (pish->PointerToRawData + pish->SizeOfRawData), &dwBytesWritten, NULL) == 0)
				{
					CloseHandle(hFile);
					MessageBox(hDlg, "Could not write to file!", "Cryptic", MB_ICONERROR);
					EnableControls(hDlg, TRUE);
					return TRUE;
				}
				CloseHandle(hFile);
			}
			MessageBox(hDlg, "File successfully crypted!", "Cryptic", MB_ICONINFORMATION);
			EnableControls(hDlg, TRUE);
			break;
		case IDC_ABOUT:
			MessageBox(hDlg, "Cryptic v3.0\nCoded by Tughack", "About", MB_ICONINFORMATION);
			break;
		case IDC_EXIT:
			EndDialog(hDlg, 0);
			break;
		}
	}
	return FALSE;
}
int main(int argc, char *argv[])
	{
	TINYCLR_SSL_FILE *in=NULL,*out=NULL;
	char *infile=NULL,*outfile=NULL,*keystr=NULL;
	RC4_KEY key;
	char buf[BUFSIZ];
	int badops=0,i;
	char **pp;
	unsigned char md[MD5_DIGEST_LENGTH];

	argc--;
	argv++;
	while (argc >= 1)
		{
		if 	(TINYCLR_SSL_STRCMP(*argv,"-in") == 0)
			{
			if (--argc < 1) goto bad;
			infile= *(++argv);
			}
		else if (TINYCLR_SSL_STRCMP(*argv,"-out") == 0)
			{
			if (--argc < 1) goto bad;
			outfile= *(++argv);
			}
		else if (TINYCLR_SSL_STRCMP(*argv,"-key") == 0)
			{
			if (--argc < 1) goto bad;
			keystr= *(++argv);
			}
		else
			{
			TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR,"unknown option %s\n",*argv);
			badops=1;
			break;
			}
		argc--;
		argv++;
		}

	if (badops)
		{
bad:
		for (pp=usage; (*pp != NULL); pp++)
			TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR,"%s",*pp);
		TINYCLR_SSL_EXIT(1);
		}

	if (infile == NULL)
		in=OPENSSL_TYPE__FILE_STDIN;
	else
		{
		in=TINYCLR_SSL_FOPEN(infile,"r");
		if (in == NULL)
			{
			TINYCLR_SSL_PERROR("open");
			TINYCLR_SSL_EXIT(1);
			}

		}
	if (outfile == NULL)
		out=OPENSSL_TYPE__FILE_STDOUT;
	else
		{
		out=TINYCLR_SSL_FOPEN(outfile,"w");
		if (out == NULL)
			{
			TINYCLR_SSL_PERROR("open");
			TINYCLR_SSL_EXIT(1);
			}
		}
		
#ifdef OPENSSL_SYS_MSDOS
	/* This should set the file to binary mode. */
	{
#include <fcntl.h>
	setmode(fileno(in),O_BINARY);
	setmode(fileno(out),O_BINARY);
	}
#endif

	if (keystr == NULL)
		{ /* get key */
		i=EVP_read_pw_string(buf,BUFSIZ,"Enter RC4 password:"******"bad password read\n");
			TINYCLR_SSL_EXIT(1);
			}
		keystr=buf;
		}

	EVP_Digest((unsigned char *)keystr,TINYCLR_SSL_STRLEN(keystr),md,NULL,EVP_md5(),NULL);
	OPENSSL_cleanse(keystr,TINYCLR_SSL_STRLEN(keystr));
	RC4_set_key(&key,MD5_DIGEST_LENGTH,md);
	
	for(;;)
		{
		i=TINYCLR_SSL_FREAD(buf,1,BUFSIZ,in);
		if (i == 0) break;
		if (i < 0)
			{
			TINYCLR_SSL_PERROR("read");
			TINYCLR_SSL_EXIT(1);
			}
		RC4(&key,(unsigned int)i,(unsigned char *)buf,
			(unsigned char *)buf);
		i=TINYCLR_SSL_FWRITE(buf,(unsigned int)i,1,out);
		if (i != 1)
			{
			TINYCLR_SSL_PERROR("write");
			TINYCLR_SSL_EXIT(1);
			}
		}
	TINYCLR_SSL_FCLOSE(out);
	TINYCLR_SSL_FCLOSE(in);
	TINYCLR_SSL_EXIT(0);
	return(1);
	}
Example #10
0
//--------------------------------------------------
// lib1x_authxmitsm_key_transmit:
//  This function has the initialization for entry to state Key_Transmit for the
//  Authenticator Key Transmit State Machine.
//--------------------------------------------------
void lib1x_kxsm_key_transmit( Auth_Pae * auth_pae, Global_Params * global, Auth_KeyxmitSM *  key_sm )
{


	struct lib1x_ethernet * eth;
	struct lib1x_eapol * eapol;
	struct lib1x_eapolkey_dot1x *eapol_key;

	OCTET_STRING	ocCounter;
	u_long		ulKeyLen = 5;
	RC4_KEY         rc4key;

	//TODO read default key with ioctl
	/*
	u_char		szDefaultKey[16] = {0x11, 0x11,0x11, 0x11,0x11, 0x11,0x11, 0x11,
	 				    0x11, 0x11,0x11, 0x11,0x11, 0x11,0x11, 0x11};
	*/
	u_char 		szIV[16] = {0x22, 0x22,0x22, 0x22,0x22, 0x22,0x22, 0x22,
	 			    0x22, 0x22,0x22, 0x22,0x22, 0x22,0x22, 0x22};
	u_char		szKeyBuf[64];


	// Set the from / to ethernet addresses.
	memset(auth_pae->sendBuffer, 0, 100);
	eth = ( struct lib1x_ethernet * ) auth_pae->sendBuffer;
	memcpy ( eth->ether_dhost, auth_pae->supp_addr, ETHER_HDRLEN);
	memcpy ( eth->ether_shost, auth_pae->global->TxRx->oursupp_addr, ETHER_HDRLEN);
	eth->ether_type = htons( LIB1X_ETHER_EAPOL_TYPE );

	eapol = ( struct lib1x_eapol * )( auth_pae->sendBuffer + ETHER_HDRLEN );
	eapol->protocol_version = LIB1X_EAPOL_VER;
	eapol->packet_type = LIB1X_EAPOL_KEY;


	if(global->RSNVariable.UnicastCipher == DOT11_ENC_WEP40)
		ulKeyLen = 5;
	else if(global->RSNVariable.UnicastCipher == DOT11_ENC_WEP104)
		ulKeyLen = 13;
	//
	else if(global->RSNVariable.UnicastCipher == DOT11_ENC_NONE)
		ulKeyLen = 13;
	//

	if(auth_pae->sendreplyready == TRUE)
	{

		//----------------------------------------
		//(1)Send Group Key using default key
		//----------------------------------------

		eapol_key = (struct lib1x_eapolkey_dot1x *) ( ( (u_char *) eapol) + LIB1X_EAPOL_HDRLEN );

		eapol_key->type = LIB1X_KEY_TYPE_RC4;
		lib1x_S2N(ulKeyLen, (u_char*)&eapol_key->length);

		ocCounter.Octet = (u_char*)malloc(LIB1X_RC_LEN);
		ocCounter.Length = LIB1X_RC_LEN;
		ReplayCounter_LI2OC(ocCounter, &global->auth->Dot1xKeyReplayCounter);
		memcpy(eapol_key->counter, ocCounter.Octet, LIB1X_RC_LEN);
		INCLargeInteger(&global->auth->Dot1xKeyReplayCounter);

		//printf("Higg = %d, Low = %d\n", global->auth->Dot1xKeyReplayCounter.field.HighPart,
		//global->auth->Dot1xKeyReplayCounter.field.LowPart);

		//TODO:Generate Random number as Key IV
		memcpy(eapol_key->iv, szIV, LIB1X_IV_LEN);
		eapol_key->index = 0;
		eapol_key->index |= (EAPOL_GROUP_KEY|EAPOL_GROUP_INDEX);


		memcpy(szKeyBuf, szIV, LIB1X_IV_LEN);
		memcpy(&szKeyBuf[16], global->RadiusKey.RecvKey.Octet, global->RadiusKey.RecvKey.Length);
		RC4_set_key(&rc4key, LIB1X_IV_LEN + global->RadiusKey.RecvKey.Length, szKeyBuf);
		//lib1x_hexdump2(MESS_DBG_RAD, "TestFun", szKeyBuf, LIB1X_IV_LEN + global->RadiusKey.RecvKey.Length, "szKeyBuf");

		//Need to be removed
		/*
		memcpy(	global->auth->gk_sm->GTK[global->auth->gk_sm->GN] ,
			szDefaultKey,
			global->RSNVariable.MulticastCipher == DOT11_ENC_WEP40 ? 5:13);
		*/
		//RC4(&rc4key, ulKeyLen, (u_char*)szDefaultKey, (u_char*)(eapol_key->material));
		RC4(&rc4key, ulKeyLen, (u_char*)global->auth->WepGroupKey, (u_char*)(eapol_key->material));

		eapol->packet_body_length = htons(LIB1X_EAPOLKEY_HDRLEN + ulKeyLen);
		//lib1x_hexdump2(MESS_DBG_KXSM, "lib1x_kxsm_key_transmit", auth_pae->sendBuffer, 100, "snedBuffer");
		memset(eapol_key->mic, 0, sizeof(eapol_key->mic));

		hmac_md5((u_char*)eapol,
			  LIB1X_EAPOL_HDRLEN + LIB1X_EAPOLKEY_HDRLEN + ulKeyLen,
			  global->RadiusKey.SendKey.Octet,
			  global->RadiusKey.SendKey.Length,
			  eapol_key->mic);

		auth_pae->sendbuflen = ETHER_HDRLEN + LIB1X_EAPOL_HDRLEN + LIB1X_EAPOLKEY_HDRLEN + ulKeyLen;
#ifdef ALLOW_DBG_KXSM
		lib1x_hexdump2(MESS_DBG_KXSM, "lib1x_kxsm_key_transmit", auth_pae->sendBuffer, auth_pae->sendbuflen, "Send EAPOL-KEY of Group Key");
#endif

		if(global->auth->RSNVariable.MulticastCipher == DOT11_ENC_WEP40 ||
			global->auth->RSNVariable.MulticastCipher == DOT11_ENC_WEP104)
			lib1x_nal_send( auth_pae->global->TxRx->network_supp, auth_pae->sendBuffer,
				auth_pae->sendbuflen );

		lib1x_control_SetGTK(global);

 		//----------------------------------------
		//(2)Send Key-mapping-Key
		//----------------------------------------


		eapol_key = (struct lib1x_eapolkey_dot1x *) ( ( (u_char *) eapol) + LIB1X_EAPOL_HDRLEN );

		eapol_key->type = LIB1X_KEY_TYPE_RC4;
		lib1x_S2N(ulKeyLen, (u_char*)&eapol_key->length);

		ocCounter.Length = LIB1X_RC_LEN;
		ReplayCounter_LI2OC(ocCounter, &global->auth->Dot1xKeyReplayCounter);
		memcpy(eapol_key->counter, ocCounter.Octet, LIB1X_RC_LEN);
		INCLargeInteger(&global->auth->Dot1xKeyReplayCounter);

		//printf("Higg = %d, Low = %d\n", global->auth->Dot1xKeyReplayCounter.field.HighPart,
		//global->auth->Dot1xKeyReplayCounter.field.LowPart);

		//TODO:Generate Random number as Key IV
		memcpy(eapol_key->iv, szIV, LIB1X_IV_LEN);
		eapol_key->index = 0;
		eapol_key->index |= (EAPOL_PAIRWISE_KEY|EAPOL_PAIRWISE_INDEX);



		eapol->packet_body_length = htons(LIB1X_EAPOLKEY_HDRLEN);
		memset(eapol_key->mic, 0, sizeof(eapol_key->mic));

		hmac_md5((u_char*)eapol,
			  LIB1X_EAPOL_HDRLEN + LIB1X_EAPOLKEY_HDRLEN,
			  global->RadiusKey.SendKey.Octet,
			  global->RadiusKey.SendKey.Length,
			  eapol_key->mic);

		auth_pae->sendbuflen = ETHER_HDRLEN + LIB1X_EAPOL_HDRLEN + LIB1X_EAPOLKEY_HDRLEN;
#ifdef ALLOW_DBG_KXSM
		lib1x_hexdump2(MESS_DBG_KXSM, "lib1x_kxsm_key_transmit", auth_pae->sendBuffer, auth_pae->sendbuflen, "Send EAPOL-KEY of key-mapping-key");
#endif
		if(global->RSNVariable.UnicastCipher == DOT11_ENC_WEP40 ||
			global->RSNVariable.UnicastCipher == DOT11_ENC_WEP104)
                	lib1x_nal_send( auth_pae->global->TxRx->network_supp,
					auth_pae->sendBuffer,auth_pae->sendbuflen );


 		//----Set key-mapping key to driver
		//----Key Mapping is for 5280
		//lib1x_control_KeyMapping(global, KEYMAP_OPERATION_SET, WEP_MODE_ON_40, KEYMAP_VALID_ON);
		//----SetPTK is for software encryption

		lib1x_control_SetPORT(global, DOT11_PortStatus_Authorized);
		lib1x_control_SetPTK(global);

	}

	//lib1x_authxmitsm_txKey( auth_pae , global->currentId );	// TODO

	auth_pae->sendreplyready = FALSE;
	key_sm->keyAvailable = FALSE;
	global->RadiusKey.Status = MPPE_SDRCKEY_NONAVALIABLE;

	free(ocCounter.Octet);

}
Example #11
0
void recv_cb(EV_P_ ev_io *watcher, int revents) {
    if(EV_ERROR & revents)
    {
        printf("error event in read");
        return;
    }
    struct conn_ctx *conn_ctx = (struct conn_ctx *)watcher;
    struct conn *conn = conn_ctx->conn;
    struct conn *another = conn->another;
    char **buf = &another->buf;

    if(conn->type == 0) {
        ev_timer_again(EV_A_ &conn->recv_ctx->watcher);
    } else {
        ev_timer_again(EV_A_ &another->recv_ctx->watcher);
    }

    ssize_t r = recv(conn->fd, *buf, BUFSIZE, 0);

    if(debug)
        printf("fd %d --------> recv %d\n", conn->fd, r);

    if(r == 0) {
        close_and_free(EV_A_ conn->another);
        close_and_free(EV_A_ conn);
        return ;
    } else if (r < 0) {
        if(errno == EAGAIN || errno == EWOULDBLOCK) {
            return ;

        } else {
            close_and_free(EV_A_ conn->another);
            close_and_free(EV_A_ conn);
            return ;
        }
    }

    RC4(&conn->key, r, *buf, *buf);

    int s = send(another->fd, *buf, r, 0);

    if(debug)
        printf("send to fd %d --------> %d\n", another->fd, s);

    if(s == -1) {
        if(errno == EAGAIN || errno == EWOULDBLOCK) {
            another->buf_len = r;
            another->buf_idx = 0;
            ev_io_stop(EV_A_ &conn->recv_ctx->io);

            ev_io_start(EV_A_ &another->send_ctx->io);
        } else {
            close_and_free(EV_A_ conn->another);
            close_and_free(EV_A_ conn);

        }
        return ;
    } else if(s < r) {
        another->buf_len = r-s;
        another->buf_idx = s;
        ev_io_stop(EV_A_ &conn->recv_ctx->io);
        ev_io_start(EV_A_ &another->send_ctx->io);
    }
    return ;
}
Example #12
0
int main(int argc, char *argv[])
	{
	FILE *in=NULL,*out=NULL;
	char *infile=NULL,*outfile=NULL,*keystr=NULL;
	RC4_KEY key;
	char buf[BUFSIZ];
	int badops=0,i;
	char **pp;
	unsigned char md[MD5_DIGEST_LENGTH];

	argc--;
	argv++;
	while (argc >= 1)
		{
		if 	(strcmp(*argv,"-in") == 0)
			{
			if (--argc < 1) goto bad;
			infile= *(++argv);
			}
		else if (strcmp(*argv,"-out") == 0)
			{
			if (--argc < 1) goto bad;
			outfile= *(++argv);
			}
		else if (strcmp(*argv,"-key") == 0)
			{
			if (--argc < 1) goto bad;
			keystr= *(++argv);
			}
		else
			{
			fprintf(stderr,"unknown option %s\n",*argv);
			badops=1;
			break;
			}
		argc--;
		argv++;
		}

	if (badops)
		{
bad:
		for (pp=usage; (*pp != NULL); pp++)
			fprintf(stderr,*pp);
		exit(1);
		}

	if (infile == NULL)
		in=stdin;
	else
		{
		in=fopen(infile,"r");
		if (in == NULL)
			{
			perror("open");
			exit(1);
			}

		}
	if (outfile == NULL)
		out=stdout;
	else
		{
		out=fopen(outfile,"w");
		if (out == NULL)
			{
			perror("open");
			exit(1);
			}
		}
		
#ifdef MSDOS
	/* This should set the file to binary mode. */
	{
#include <fcntl.h>
	setmode(fileno(in),O_BINARY);
	setmode(fileno(out),O_BINARY);
	}
#endif

	if (keystr == NULL)
		{ /* get key */
		i=EVP_read_pw_string(buf,BUFSIZ,"Enter RC4 password:"******"bad password read\n");
			exit(1);
			}
		keystr=buf;
		}

	MD5((unsigned char *)keystr,(unsigned long)strlen(keystr),md);
	OPENSSL_cleanse(keystr,strlen(keystr));
	RC4_set_key(&key,MD5_DIGEST_LENGTH,md);
	
	for(;;)
		{
		i=fread(buf,1,BUFSIZ,in);
		if (i == 0) break;
		if (i < 0)
			{
			perror("read");
			exit(1);
			}
		RC4(&key,(unsigned int)i,(unsigned char *)buf,
			(unsigned char *)buf);
		i=fwrite(buf,(unsigned int)i,1,out);
		if (i != 1)
			{
			perror("write");
			exit(1);
			}
		}
	fclose(out);
	fclose(in);
	exit(0);
	return(1);
	}
Example #13
0
int main(int argc, char *argv[])
{
    int i, err = 0;
    int j;
    unsigned char *p;
    RC4_KEY key;
    unsigned char obuf[512];

# if !defined(OPENSSL_PIC)
    void OPENSSL_cpuid_setup(void);

    OPENSSL_cpuid_setup();
# endif

    for (i = 0; i < 6; i++) {
        RC4_set_key(&key, keys[i][0], &(keys[i][1]));
        sgx_memset(obuf, 0x00, sizeof(obuf));
        RC4(&key, data_len[i], &(data[i][0]), obuf);
        if (sgx_memcmp(obuf, output[i], data_len[i] + 1) != 0) {
            printf("error calculating RC4\n");
            printf("output:");
            for (j = 0; j < data_len[i] + 1; j++)
                printf(" %02x", obuf[j]);
            printf("\n");
            printf("expect:");
            p = &(output[i][0]);
            for (j = 0; j < data_len[i] + 1; j++)
                printf(" %02x", *(p++));
            printf("\n");
            err++;
        } else
            printf("test %d ok\n", i);
    }
    printf("test end processing ");
    for (i = 0; i < data_len[3]; i++) {
        RC4_set_key(&key, keys[3][0], &(keys[3][1]));
        sgx_memset(obuf, 0x00, sizeof(obuf));
        RC4(&key, i, &(data[3][0]), obuf);
        if ((sgx_memcmp(obuf, output[3], i) != 0) || (obuf[i] != 0)) {
            printf("error in RC4 length processing\n");
            printf("output:");
            for (j = 0; j < i + 1; j++)
                printf(" %02x", obuf[j]);
            printf("\n");
            printf("expect:");
            p = &(output[3][0]);
            for (j = 0; j < i; j++)
                printf(" %02x", *(p++));
            printf(" 00\n");
            err++;
        } else {
            printf(".");
            fflush(stdout);
        }
    }
    printf("done\n");
    printf("test multi-call ");
    for (i = 0; i < data_len[3]; i++) {
        RC4_set_key(&key, keys[3][0], &(keys[3][1]));
        sgx_memset(obuf, 0x00, sizeof(obuf));
        RC4(&key, i, &(data[3][0]), obuf);
        RC4(&key, data_len[3] - i, &(data[3][i]), &(obuf[i]));
        if (sgx_memcmp(obuf, output[3], data_len[3] + 1) != 0) {
            printf("error in RC4 multi-call processing\n");
            printf("output:");
            for (j = 0; j < data_len[3] + 1; j++)
                printf(" %02x", obuf[j]);
            printf("\n");
            printf("expect:");
            p = &(output[3][0]);
            for (j = 0; j < data_len[3] + 1; j++)
                printf(" %02x", *(p++));
            err++;
        } else {
            printf(".");
            fflush(stdout);
        }
    }
    printf("done\n");
    printf("bulk test ");
    {
        unsigned char buf[513];
        SHA_CTX c;
        unsigned char md[SHA_DIGEST_LENGTH];
        static unsigned char expected[] = {
            0xa4, 0x7b, 0xcc, 0x00, 0x3d, 0xd0, 0xbd, 0xe1, 0xac, 0x5f,
            0x12, 0x1e, 0x45, 0xbc, 0xfb, 0x1a, 0xa1, 0xf2, 0x7f, 0xc5
        };

        RC4_set_key(&key, keys[0][0], &(keys[3][1]));
        sgx_memset(buf, '\0', sizeof(buf));
        SHA1_Init(&c);
        for (i = 0; i < 2571; i++) {
            RC4(&key, sizeof(buf), buf, buf);
            SHA1_Update(&c, buf, sizeof(buf));
        }
        SHA1_Final(md, &c);

        if (sgx_memcmp(md, expected, sizeof(md))) {
            printf("error in RC4 bulk test\n");
            printf("output:");
            for (j = 0; j < (int)sizeof(md); j++)
                printf(" %02x", md[j]);
            printf("\n");
            printf("expect:");
            for (j = 0; j < (int)sizeof(md); j++)
                printf(" %02x", expected[j]);
            printf("\n");
            err++;
        } else
            printf("ok\n");
    }
# ifdef OPENSSL_SYS_NETWARE
    if (err)
        printf("ERROR: %d\n", err);
# endif
    EXIT(err);
    return (0);
}
Example #14
0
void send_mcast(struct params *p, unsigned char x)
{
	struct ieee80211_frame *wh;
	short *seq;
	struct queue *q = p->q;
	char *data, *ptr;
	int len;
	uLong crc = crc32(0L, Z_NULL, 0);
	uLong *pcrc;
	int i;
	int need_frag = 0;
	char payload[10] = "\xAA\xAA\x03\x00\x00\x00\x08\x06\x00\x00";

	assert(q);

	/* 802.11 */
	memset(p->packet, 0, sizeof(p->packet));
	wh = (struct ieee80211_frame*) p->packet;
	wh->i_fc[0] |= IEEE80211_FC0_TYPE_DATA;
	wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_DATA;
	wh->i_fc[1] |= IEEE80211_FC1_DIR_TODS;
	wh->i_fc[1] |= IEEE80211_FC1_WEP;
	
	wh->i_dur[0] = 0x69;
	
	memcpy(wh->i_addr1, p->ap, 6);
	memcpy(wh->i_addr2, p->mac, 6);
	memcpy(wh->i_addr3, p->mcast, 5);
	wh->i_addr3[5] = x;

	seq = (short*) wh->i_seq;
	*seq = seqfn(p->seq++, 0);

	/* IV */
	data = (char*) (wh+1);
	ptr = (char*) (q->wh+1);
	memcpy(data, ptr, 3);

	if (p->prga_len == 0) {
	
		RC4_KEY k;
		unsigned char key[8];

		memset(&key[3], 0x61, 5);
		memcpy(key, (q->wh+1), 3);
		p->prga_len = 128;

		RC4_set_key(&k, 8, key);
		memset(p->prga, 0, sizeof(p->prga));
		RC4(&k, p->prga_len, p->prga, p->prga);

		
#if 0	
		int ptl = q->len;
		char *pt;

		pt = known_pt(q->wh, &ptl);
		ptr += 4;
		p->prga_len = ptl;
		for (i = 0; i < p->prga_len; i++)
			p->prga[i] = ptr[i] ^ pt[i];
#endif			
	}

	/* data */
	data += 4;
	memcpy(data, payload, sizeof(payload));
	p->prga_len = 12;
	len = p->prga_len + 1 - 4;

#if 1
	if (len < sizeof(payload)) {
		need_frag = len;
		wh->i_fc[1] |= IEEE80211_FC1_MORE_FRAG;
	}	
#endif

	/* crc */
	pcrc = (uLong*) (data+len);
	*pcrc = crc32(crc, data, len);

	/* wepify */
	len += 4;
	for (i = 0; i < (len); i++) {
		assert( i <= p->prga_len);
		data[i] ^= p->prga[i];
	}
//	data[i] ^= x;

	len += sizeof(*wh);
	p->packet_len = len + 4;
	send_packet(p);

	/* the data we sent is too f*****g short */
	if (need_frag) {
		memset(data, 0, len);

		/* 802.11 */
		*seq = seqfn(p->seq-1, 1);
		wh->i_fc[1] &= ~IEEE80211_FC1_MORE_FRAG;

		/* data */
		len = sizeof(payload) - need_frag;
		assert(len > 0 && len <= (p->prga_len - 4));
		memcpy(data, &payload[need_frag], len);
	
		/* crc */
		crc = crc32(0L, Z_NULL, 0);
		len = p->prga_len - 4;
		pcrc = (uLong*) (data+len);
		*pcrc = crc32(crc, data, len);

		/* wepify */
		len += 4;
		for (i = 0; i < len; i++) {
			assert( i < p->prga_len);
			data[i] ^= p->prga[i];
		}

		len += sizeof(*wh) + 4;
		p->packet_len = len;
		send_packet(p);
	}
}
Example #15
0
void crypto_rc4(CryptoRc4 rc4, UINT32 length, const BYTE* in_data, BYTE* out_data)
{
	RC4(&rc4->rc4_key, length, in_data, out_data);
}
int ssl_test_rc4(int argc, char *argv[])
	{
	int i,err=0;
	int j;
	unsigned char *p;
	RC4_KEY key;
	unsigned char obuf[512];

	for (i=0; i<6; i++)
		{
		RC4_set_key(&key,keys[i][0],&(keys[i][1]));
		TINYCLR_SSL_MEMSET(obuf,0x00,sizeof(obuf));
		RC4(&key,data_len[i],&(data[i][0]),obuf);
		if (TINYCLR_SSL_MEMCMP(obuf,output[i],data_len[i]+1) != 0)
			{
			TINYCLR_SSL_PRINTF("error calculating RC4\n");
			TINYCLR_SSL_PRINTF("output:");
			for (j=0; j<data_len[i]+1; j++)
				TINYCLR_SSL_PRINTF(" %02x",obuf[j]);
			TINYCLR_SSL_PRINTF("\n");
			TINYCLR_SSL_PRINTF("expect:");
			p= &(output[i][0]);
			for (j=0; j<data_len[i]+1; j++)
				TINYCLR_SSL_PRINTF(" %02x",*(p++));
			TINYCLR_SSL_PRINTF("\n");
			err++;
			}
		else
			TINYCLR_SSL_PRINTF("test %d ok\n",i);
		}
	TINYCLR_SSL_PRINTF("test end processing ");
	for (i=0; i<data_len[3]; i++)
		{
		RC4_set_key(&key,keys[3][0],&(keys[3][1]));
		TINYCLR_SSL_MEMSET(obuf,0x00,sizeof(obuf));
		RC4(&key,i,&(data[3][0]),obuf);
		if ((TINYCLR_SSL_MEMCMP(obuf,output[3],i) != 0) || (obuf[i] != 0))
			{
			TINYCLR_SSL_PRINTF("error in RC4 length processing\n");
			TINYCLR_SSL_PRINTF("output:");
			for (j=0; j<i+1; j++)
				TINYCLR_SSL_PRINTF(" %02x",obuf[j]);
			TINYCLR_SSL_PRINTF("\n");
			TINYCLR_SSL_PRINTF("expect:");
			p= &(output[3][0]);
			for (j=0; j<i; j++)
				TINYCLR_SSL_PRINTF(" %02x",*(p++));
			TINYCLR_SSL_PRINTF(" 00\n");
			err++;
			}
		else
			{
			TINYCLR_SSL_PRINTF(".");
			TINYCLR_SSL_FFLUSH(OPENSSL_TYPE__FILE_STDOUT);
			}
		}
	TINYCLR_SSL_PRINTF("done\n");
	TINYCLR_SSL_PRINTF("test multi-call ");
	for (i=0; i<data_len[3]; i++)
		{
		RC4_set_key(&key,keys[3][0],&(keys[3][1]));
		TINYCLR_SSL_MEMSET(obuf,0x00,sizeof(obuf));
		RC4(&key,i,&(data[3][0]),obuf);
		RC4(&key,data_len[3]-i,&(data[3][i]),&(obuf[i]));
		if (TINYCLR_SSL_MEMCMP(obuf,output[3],data_len[3]+1) != 0)
			{
			TINYCLR_SSL_PRINTF("error in RC4 multi-call processing\n");
			TINYCLR_SSL_PRINTF("output:");
			for (j=0; j<data_len[3]+1; j++)
				TINYCLR_SSL_PRINTF(" %02x",obuf[j]);
			TINYCLR_SSL_PRINTF("\n");
			TINYCLR_SSL_PRINTF("expect:");
			p= &(output[3][0]);
			for (j=0; j<data_len[3]+1; j++)
				TINYCLR_SSL_PRINTF(" %02x",*(p++));
			err++;
			}
		else
			{
			TINYCLR_SSL_PRINTF(".");
			TINYCLR_SSL_FFLUSH(OPENSSL_TYPE__FILE_STDOUT);
			}
		}
	TINYCLR_SSL_PRINTF("done\n");
	TINYCLR_SSL_PRINTF("bulk test ");
	{   unsigned char buf[513];
	    SHA_CTX c;
	    unsigned char md[SHA_DIGEST_LENGTH];
	    static unsigned char expected[]={
		0xa4,0x7b,0xcc,0x00,0x3d,0xd0,0xbd,0xe1,0xac,0x5f,
		0x12,0x1e,0x45,0xbc,0xfb,0x1a,0xa1,0xf2,0x7f,0xc5 };

		RC4_set_key(&key,keys[0][0],&(keys[3][1]));
		TINYCLR_SSL_MEMSET(buf,'\0',sizeof(buf));
		SHA1_Init(&c);
		for (i=0;i<2571;i++) {
			RC4(&key,sizeof(buf),buf,buf);
			SHA1_Update(&c,buf,sizeof(buf));
		}
		SHA1_Final(md,&c);

		if (TINYCLR_SSL_MEMCMP(md,expected,sizeof(md))) {
			TINYCLR_SSL_PRINTF("error in RC4 bulk test\n");
			TINYCLR_SSL_PRINTF("output:");
			for (j=0; j<(int)sizeof(md); j++)
				TINYCLR_SSL_PRINTF(" %02x",md[j]);
			TINYCLR_SSL_PRINTF("\n");
			TINYCLR_SSL_PRINTF("expect:");
			for (j=0; j<(int)sizeof(md); j++)
				TINYCLR_SSL_PRINTF(" %02x",expected[j]);
			TINYCLR_SSL_PRINTF("\n");
			err++;
		}
		else	TINYCLR_SSL_PRINTF("ok\n");
	}
#ifdef OPENSSL_SYS_NETWARE
    if (err) TINYCLR_SSL_PRINTF("ERROR: %d\n", err);
#endif
	return(err);
	}