Exemplo n.º 1
0
int
main(int argc, char *argv[])
{
    struct ktc_principal client;
    struct ktc_encryptionKey sessionkey;
    Date start, end;
    afs_int32 host;
    char key[8];
    char ticket[MAXKTCTICKETLEN];
    afs_int32 ticketLen;
    afs_int32 code;
    char bob[KA_TIMESTR_LEN];

    whoami = argv[0];
    initialize_RXK_error_table();
    initialize_KA_error_table();

    if (argc != 3) {
	printf("Usage is %s key ticket\n", whoami);
	exit(1);
    }
    if (ka_ReadBytes(argv[1], key, sizeof(key)) != 8)
	printf("Key must be 8 bytes long\n");
    if (!des_check_key_parity(key) || des_is_weak_key(key)) {
	afs_com_err(whoami, KABADKEY, "server's key for decoding ticket is bad");
	exit(1);
    }
    ticketLen = ka_ReadBytes(argv[2], ticket, sizeof(ticket));
    printf("Ticket length is %d\n", ticketLen);

    code =
	tkt_DecodeTicket(ticket, ticketLen, key, client.name, client.instance,
			 client.cell, &sessionkey, &host, &start, &end);
    if (code) {
	afs_com_err(whoami, code, "decoding ticket");
	if (code = tkt_CheckTimes(start, end, time(0)) <= 0)
	    afs_com_err(whoami, 0, "because of start or end times");
	exit(1);
    }

    if (!des_check_key_parity(&sessionkey) || des_is_weak_key(&sessionkey)) {
	afs_com_err(whoami, KABADKEY, "checking ticket's session key");
	exit(1);
    }

    ka_PrintUserID("Client is ", client.name, client.instance, 0);
    if (strlen(client.cell))
	printf("@%s", client.cell);
    printf("\nSession key is ");
    ka_PrintBytes(&sessionkey, 8);
    ka_timestr(start, bob, KA_TIMESTR_LEN);
    printf("\nGood from %s", bob);
    ka_timestr(end, bob, KA_TIMESTR_LEN);
    printf(" till %s\n", bob);
}
Exemplo n.º 2
0
void openssl_des_crypt()
{
	int size;
	DES_cblock key;
	DES_cblock outputs;
	const_DES_cblock inputs;
	DES_key_schedule schedule;
	unsigned char tmp[16] = "des crypt";

	DES_random_key(&key);
	DES_string_to_key("beike2012", &key);
	DES_set_odd_parity(&key);
	des_check_key_parity(&key);
	DES_set_key_checked(&key, &schedule);
	DES_is_weak_key((const_DES_cblock *)tmp);
	DES_ecb_encrypt((const_DES_cblock *)tmp, &outputs, &schedule, DES_ENCRYPT);
	printf("\nDES_ecb_encrypt(%s) = ", tmp);
	for (size = 0; size < sizeof(outputs); size++)
		printf("%02x", outputs[size]);
	printf("\n");

	DES_ecb_encrypt(&outputs, &inputs, &schedule, DES_DECRYPT);
	printf("DES_ecb_decrypt(");
	for (size = 0; size < sizeof(outputs); size++)
		printf("%02x", outputs[size]);
	printf(") = %s\n", inputs);
}
Exemplo n.º 3
0
int
des_key_sched(des_cblock k, des_key_schedule schedule)
#endif
{
    /* better pass 8 bytes, length not checked here */

    int i, j, n;	/* i = r10, j = r9, n = r8 */
    unsigned int temp;	/*  r7 */
    char *p_char;	/* r6 */
    key k_char;
    i = 8;
    n = 0;
    p_char = k_char;

#ifdef lint
    n = n;			/* fool it in case of VAXASM */
#endif
#ifdef DEBUG
    if (des_debug)
	fprintf(stderr, "\n\ninput key, left to right = ");
#endif

    if (!des_check_key_parity(k))	/* bad parity --> return -1 */
	return (-1);

    do {
	/* get next input key byte */
#ifdef DEBUG
	if (des_debug)
	    fprintf(stderr, "%02x ", *k & 0xff);
#endif
	temp = (unsigned int)((unsigned char)*k++);
	j = 8;

	do {
#ifndef VAXASM
	    *p_char++ = (int)temp & 01;
	    temp = temp >> 1;
#else
	    asm("bicb3	$-2,r7,(r8)+[r6]");
	    asm("rotl	$-1,r7,r7");
#endif
	} while (--j > 0);
    } while (--i > 0);

#ifdef DEBUG
    if (des_debug) {
	p_char = k_char;
	fprintf(stderr, "\nKey bits, from zero to 63");
	for (i = 0; i <= 7; i++) {
	    fprintf(stderr, "\n\t");
	    for (j = 0; j <= 7; j++)
		fprintf(stderr, "%d ", *p_char++);
	}
    }
#else
#ifdef lint
    p_char = p_char;
#endif
#endif

    /* check against weak keys */
    k -= sizeof(des_cblock);

    if (des_is_weak_key(k))
	return (-2);

    make_key_sched(k_char, schedule);

    /* if key was good, return 0 */
    return 0;
}