Ejemplo n.º 1
0
int EncryptTitleKey(u8 EncTitleKey[0x10], u8 *DecTitleKey, u8 *CommonKey, u8 *TitleID)
{
	//generating IV
	u8 iv[16];
	memset(&iv,0x0,16);
	memcpy(iv,TitleID,0x8);
	
	
	//Encrypting titlekey
	ctr_aes_context ctx;
	memset(&ctx,0x0,sizeof(ctr_aes_context));
	
	ctr_init_aes_cbc(&ctx,CommonKey,iv,ENC);
	ctr_aes_cbc(&ctx,DecTitleKey,EncTitleKey,0x10,ENC);
		
	//checking titlekey encrypted properly
	u8 tmp[0x10];
	ctr_init_aes_cbc(&ctx,CommonKey,iv,DEC);
	ctr_aes_cbc(&ctx,EncTitleKey,tmp,0x10,DEC);
	
	/**
	memdump(stdout, "TitleKey:        ", DecTitleKey, 0x10);
	memdump(stdout, "Enc_TitleKey:    ", EncTitleKey, 0x10);
	memdump(stdout, "Dec_TitleKey:    ", tmp, 0x10);
	**/
	
	return memcmp(DecTitleKey,tmp,0x10);
}
Ejemplo n.º 2
0
int GenAESMAC(u8 KeyX[16], u8 KeyY[16], AESMAC_CTX *ctx)
{
	/* Generating Hash for AES MAC */
	u8 result = PrepAESMAC(ctx);
	if(result)
		return result;
	
	/* Preparing for Crypto functions */
	u8 *encrypted_hash = malloc(0x20);
	u8 *outkey = malloc(16);
	u8 IV[16];
	memset(encrypted_hash,0,0x20);
	memset(outkey,0,16);
	memset(&IV,0,16);
	
	/* Getting Key for AES MAC */
	ctr_keyscrambler(outkey,KeyX,KeyY); //Not implemented yet, as no one knows that. ATM, it's a placeholder keyscrambler for testing.
	
	/* Crypting hash */
	ctr_aes_context aes_cbc;
	ctr_init_aes_cbc(&aes_cbc,outkey,IV,ENC);
	ctr_aes_cbc(&aes_cbc,ctx->hash,encrypted_hash,0x20,ENC);
	
	if(ctx->Verbose){
		memdump(stdout," KeyX:              ",KeyX,16);
		memdump(stdout," KeyY:              ",KeyY,16);
		memdump(stdout," Normal Key:        ",outkey,16);
		memdump(stdout," Hash For MAC:      ",ctx->hash,0x20);
		memdump(stdout," MAC:               ",encrypted_hash+0x10,16);
	}
	
	
	/* Writing AES MAC to context */
	memcpy(ctx->aesmac,encrypted_hash+0x10,16);	

	free(outkey);
	free(encrypted_hash);
	return 0;
}