示例#1
0
void init_Self_NPDRM(Self_NPDRM* npdrm, char* titleid, char* filename) {
  set_u32(&npdrm->block_type, 3);
  set_u32(&npdrm->block_size, sizeof(Self_NPDRM));
  set_u32(&npdrm->magic, 0x4E504400);
  set_u32(&npdrm->unknown3, 1);
  set_u32(&npdrm->unknown4, 3);
  set_u32(&npdrm->unknown5, 1);
  strncpy(npdrm->titleid, titleid, 0x30);
  //memcpy(npdrm->hash_unknown, npdrm_hash_unknown, sizeof(npdrm_hash_unknown));

  char *true_filename = strrchr(filename,'/');
  if(true_filename == NULL) {
    true_filename = strrchr(filename,'\\');
  }
  if(true_filename == NULL) {
    true_filename = filename;
  } else {
    true_filename++;
  }
  
  u8 npdrm_omac_key[0x10]; int i;
  for(i=0;i<0x10;i++) npdrm_omac_key[i] = npdrm_omac_key1[i] ^ npdrm_omac_key2[i];

  int buf_len = 0x30+strlen(true_filename);
  char *buf = (char*)malloc(buf_len);
  memcpy(buf, npdrm->titleid, 0x30);
  strcpy(buf+0x30, true_filename);
  aesOmac1Mode(npdrm->hash1, buf, buf_len, npdrm_omac_key3, sizeof(npdrm_omac_key3)*8);
  free(buf);
  aesOmac1Mode(npdrm->hash2, (u8*)&(npdrm->magic), 0x60, npdrm_omac_key, sizeof(npdrm_omac_key)*8);
}
示例#2
0
int create_npd_controlflag_payload(npdrm_encrypt_info_t *npdrm_opt, npdrm_info_t *payload) {
  uint8_t klic[16];
  static uint8_t unknown_hash[16] = { "watermarktrololo" };
  
  keyset_t *np_tid = find_keyset_by_name("NP_tid");
  keyset_t *np_ci = find_keyset_by_name("NP_ci");

  if (!np_tid || !np_ci)
    return 0;
	
  if (klicensee) {
    memcpy(klic, klicensee, 16);
  } else if (npdrm_opt->license_type == NPDRM_LICENSETYPE_FREE) {
    keyset_t *klic_free = find_keyset_by_name("NP_klic_free");
    if (!klic_free )
		return 0;
    memcpy(klic, klic_free->erk_key, 16);	
  } else if (npdrm_opt->license_type == NPDRM_LICENSETYPE_LOCAL) {
	if (!decrypt_klicensee(npdrm_opt->content_id, klic))
		return 0;
  } else
	return 0;

  payload->magic = NPDRM_MAGIC; // 0x4E504400
  payload->unknown0 = 1;
  payload->license_type = npdrm_opt->license_type;
  payload->type = npdrm_opt->app_type;
  memcpy(payload->content_id, npdrm_opt->content_id, sizeof(payload->content_id));
  memcpy(payload->hash, unknown_hash, sizeof(unknown_hash));
  payload->unknown1 = 0;
  payload->unknown2 = 0;
  npd_controlflag_payload_adjust_endianness(payload);
  
  int i = 0;
  uint8_t key[16];

  uint8_t *np_ci_key = np_ci->erk_key;
  // Xor the klic key.
  while (i< 0x10) {
	key[i] = np_ci_key[i] ^ klic[i];
	++i;
  }

  int len = strlen(npdrm_opt->real_filename) + sizeof(payload->content_id);
  char *buffer = malloc(len + 1);
  memcpy(buffer, payload->content_id, sizeof(payload->content_id));
  strcpy(buffer + sizeof(payload->content_id), npdrm_opt->real_filename);
    
  aesOmac1Mode(payload->hash_iv,  (uint8_t *) buffer, len, np_tid->erk_key, 128);
  aesOmac1Mode(payload->hash_xor, (uint8_t *) payload, 0x60, key, 128);
  return 1;
}