Ejemplo n.º 1
0
void testGetByte()
{
	byte_t byte=0;
	Bitset<32> bits(0x10203040);
	byte = bits.GetByte(0, 8);
	PrintBytes(&byte, 1);
	byte = bits.GetByte(8, 8);
	PrintBytes(&byte, 1);
	byte = bits.GetByte(16, 8);
	PrintBytes(&byte, 1);
	byte = bits.GetByte(24, 8);
	PrintBytes(&byte, 1);
}
Ejemplo n.º 2
0
VOID EFIAPI
OvrResetSystem(
	IN EFI_RESET_TYPE	ResetType,
	IN EFI_STATUS		ResetStatus,
	IN UINTN			DataSize,
	IN VOID				*ResetData
)
{
	
	PRINT("->ResetSystem(%s, %r, %x, %p)\n", EfiResetType[ResetType], ResetStatus, DataSize, ResetData);
	PrintBytes((CHAR8 *)ResetData, DataSize);
//	gOrgRS.ResetSystem(ResetType, ResetStatus, DataSize, ResetData);
}
Ejemplo n.º 3
0
int TestUnicode(void)
{
//const char *text = "Sפn bפn de magnא el vיder, el me fa minga mal.";
  uchar* buffer = NULL;
  const char* text = "באהגיטכךםלןמףעצפתש��‎�חסץד";
  int   length = 0;
  int   errors = 1;
  bool  doBom  = true;
  bool  foundBOM = false;

  PrintBytes((void*)text,(int)strlen(text));

  // Try to convert to Unicode UTF-16
  if(TryCreateWideString(text,"",doBom,&buffer,length))
  {
    PrintBytes(buffer,length);

    CString result;
    if(TryConvertWideString(buffer,length,"",result,foundBOM))
    {
      PrintBytes((void*)result.GetString(),result.GetLength());
    }
    // Do not forget to free the buffer
    delete [] buffer;

    if(text == result)
    {
      --errors;
    }
  }

  // SUMMARY OF THE TEST
  printf("Testcase                                         Result\n");
  printf("---------------------------------------------- - ------\n");
  printf("Testing Unicode conversions on diacritic chars : %s\n",errors ? "ERROR" : "OK");

  return errors;
}
Ejemplo n.º 4
0
int CreateRandomBytes(const char *name, int size)
{
    unsigned char *buff = (unsigned char*)malloc(size);
    if (buff)
    {
        GetRandomBytes(buff, size);
        PrintBytes(name, buff, size);
        free(buff);
        return 0;
    }

    fprintf(stderr, "Insufficient memory error.\n");
    return 1;
}
Ejemplo n.º 5
0
int CreateSignTestVector(const char *seed, const char *msg)
{
    unsigned char md[SHA512_DIGEST_LENGTH];
    unsigned char Kpub[ed25519_public_key_size];
    unsigned char Kprv[ed25519_private_key_size];
    unsigned char sig[ed25519_signature_size];
    int len = (int)strlen(msg);

    if (seed)
    {
        SHA512_CTX H;
        SHA512_Init(&H);
        SHA512_Update(&H, seed, strlen(seed));
        SHA512_Final(md, &H);
    }
    else
    {
        GetRandomBytes(md, 32);
    }

    PrintBytes("sk", md, 32);
    ed25519_CreateKeyPair(Kpub, Kprv, 0, md);

    PrintBytes("Kpub", Kpub, ed25519_public_key_size);
    PrintBytes("Kprv", Kprv, ed25519_private_key_size);

    PrintBytes("m", (const unsigned char*)msg, len);
    ed25519_SignMessage(sig, Kprv, 0, (const unsigned char*)msg, len);
    PrintBytes("sig", sig, ed25519_signature_size);

    if (ed25519_VerifySignature(sig, Kpub, (const unsigned char*)msg, len))
        return 0;

    fprintf(stderr, "Signature verification failed.\n");
    return 1;
}
Ejemplo n.º 6
0
EFI_STATUS EFIAPI
OvrSetVariable(
	IN CHAR16			*VariableName,
	IN EFI_GUID			*VendorGuid,
	IN UINT32			Attributes,
	IN UINTN			DataSize,
	IN VOID				*Data
)
{
	EFI_STATUS			Status;
	
	Status = gOrgRS.SetVariable(VariableName, VendorGuid, Attributes, DataSize, Data);
	//PRINT("->SetVariable(%s)\n", VariableName);
	PRINT("->SetVariable(%s, %s, %x, %x, %p) = %r\n", VariableName, GuidStr(VendorGuid), Attributes, DataSize, Data, Status);
	PrintBytes((CHAR8 *)Data, DataSize);
	//PRINT("->SetVariable(%s)\n", VariableName);
	return Status;
}
Ejemplo n.º 7
0
EFI_STATUS EFIAPI
OvrGetVariable(
	IN CHAR16			*VariableName,
	IN EFI_GUID			*VendorGuid,
	OUT UINT32			*Attributes,
	IN OUT UINTN		*DataSize,
	OUT VOID			*Data
)
{
	EFI_STATUS			Status;
	UINT32				OurAttributes;
	
	
	//
	// Attributes could be NULL, but it's still good
	// to get and see them.
	//
	if (Attributes != NULL) {
		OurAttributes = *Attributes;
	}
	Status = gOrgRS.GetVariable(VariableName, VendorGuid, &OurAttributes, DataSize, Data);
	if (Attributes != NULL) {
		*Attributes = OurAttributes;
	}
	
	#if CLEANER_LOG == 1
	// Better not print this to avoid EfiTime "SPAM" on some AMI firmware - reported by XyZ
	if (StrStr(VariableName, L"EfiTime") == 0) {
		PRINT("->GetVariable(%s, %s, %x/%x, %x, %p) = %r\n",
		        VariableName, GuidStr(VendorGuid), Attributes != NULL ? *Attributes : 0, OurAttributes, *DataSize, Data, Status);
	}
	#else
	PRINT("->GetVariable(%s, %s, %x/%x, %x, %p) = %r\n",
		VariableName, GuidStr(VendorGuid), Attributes != NULL ? *Attributes : 0, OurAttributes, *DataSize, Data, Status);
	//PRINT("->GetVariable(%s)\n", VariableName);
	#endif
	
	if (!EFI_ERROR(Status)) {
		PrintBytes((CHAR8 *)Data, *DataSize);
	}
	return Status;
}
Ejemplo n.º 8
0
Archivo: Lib.c Proyecto: jief666/clover
/** Prints RT vars. */
VOID
EFIAPI
PrintRTVariables(
	IN EFI_RUNTIME_SERVICES	*RT
)
{
	EFI_STATUS		Status;
	UINT32			Attributes;
	//UINT64			MaximumVariableStorageSize;
	//UINT64			RemainingVariableStorageSize;
	//UINT64			MaximumVariableSize;
	UINTN			VariableNameSize;
	UINTN			VariableNameBufferSize;
	UINTN			VariableDataSize;
	EFI_GUID		VendorGuid;
	BOOLEAN			IsDataPrintDisabled;
	
	//
	// Print storage info
	//
	/*
	PRINT("Vars storage:\n");
	PRINT("   Attrib: MaximumVariableStorageSize, RemainingVariableStorageSize, MaximumVariableSize\n");
	// NV+BS
	PRINT(" NV+BS   : ");
	Attributes = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS;
	Status = RT->QueryVariableInfo(Attributes, &MaximumVariableStorageSize, &RemainingVariableStorageSize, &MaximumVariableSize);
	if (EFI_ERROR(Status)) {
		PRINT("%r\n", Status);
	} else {
		PRINT("%ld, %ld, %ld\n", MaximumVariableStorageSize, RemainingVariableStorageSize, MaximumVariableSize);
	}
	// NV+BS+RT
	PRINT(" NV+BS+RT: ");
	Attributes = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
	Status = RT->QueryVariableInfo(Attributes, &MaximumVariableStorageSize, &RemainingVariableStorageSize, &MaximumVariableSize);
	if (EFI_ERROR(Status)) {
		PRINT("%r\n", Status);
	} else {
		PRINT("%ld, %ld, %ld\n", MaximumVariableStorageSize, RemainingVariableStorageSize, MaximumVariableSize);
	}
	*/
	
	//
	// Print all vars
	//
	PRINT("Variables:\n");
	VariableNameBufferSize = VARIABLE_NAME_BUFFER_SIZE;
	if (gVariableNameBuffer == NULL) {
		// init var name buffer
		// note: this must be called during boot services,
		// so if vars are going to be printed during runtime
		// they must be first printed during boot services
		// to init this buffer.
		if (InBootServices) {
			gVariableNameBuffer = AllocateRuntimePool(VariableNameBufferSize);
		} else {
			// error: buffer not inited during boot services
			PRINT("ERROR: gVariableNameBuffer not inited\n");
			return;
		}
	}
	// first call to GetNextVariableName must be with empty string
	gVariableNameBuffer[0] = L'\0';
	
	while (TRUE) {
		VariableNameSize = VariableNameBufferSize;
		Status = RT->GetNextVariableName(&VariableNameSize, gVariableNameBuffer, &VendorGuid);
		
		if (Status == EFI_BUFFER_TOO_SMALL) {
			// we will not handle this to avoid problems during calling in runtime
			PRINT("ERROR: gVariableNameBuffer too small\n");
			return;
		}
		if (Status == EFI_NOT_FOUND) {
			// no more vars
			break;
		}
		if (EFI_ERROR (Status)) {
			// no more vars or error
			PRINT("ERROR: GetNextVariableName: %r\n", Status);
			return;
		}
		
		// prepare for var data if needed
		if (gVariableDataBuffer == NULL) {
			if (InBootServices) {
				gVariableDataBuffer = AllocateRuntimePool(VARIABLE_DATA_BUFFER_SIZE);
			} else {
				// error: buffer not inited during boot services
				PRINT("ERROR: gVariableDataBuffer not inited\n");
				return;
			}
		}
		
		IsDataPrintDisabled = FALSE;
		
		#if PRINT_SHELL_VARS == 0
		{
			BOOLEAN			IsShellVar;
			
			IsShellVar = CompareGuid(&VendorGuid, &ShellInt) 
				|| CompareGuid(&VendorGuid, &SEnv) 
				|| CompareGuid(&VendorGuid, &ShellDevPathMap) 
				|| CompareGuid(&VendorGuid, &ShellProtId) 
				|| CompareGuid(&VendorGuid, &ShellAlias);
			
			IsDataPrintDisabled = IsShellVar;
		}
		#endif
		
		// get and print this var
		VariableDataSize = VARIABLE_DATA_BUFFER_SIZE;
		Status = RT->GetVariable(gVariableNameBuffer, &VendorGuid, &Attributes, &VariableDataSize, gVariableDataBuffer);
		if (EFI_ERROR(Status)) {
			PRINT(" %s:%s = %r\n", GuidStr(&VendorGuid), gVariableNameBuffer, Status);
		} else {
			PRINT("%08x ", Attributes);
			PRINT("%a", (Attributes & EFI_VARIABLE_NON_VOLATILE) ? "NV+" : "   ");
			PRINT("%a", (Attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS) ? "BS+" : "   ");
			PRINT("%a", (Attributes & EFI_VARIABLE_RUNTIME_ACCESS) ? "RT+" : "   ");
			PRINT("%a", (Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) ? "HW+" : "   ");
			PRINT(" %s:%s, DataSize = %x\n", GuidStr(&VendorGuid), gVariableNameBuffer, VariableDataSize);
			if (!IsDataPrintDisabled) {
				PrintBytes(gVariableDataBuffer, VariableDataSize);
			}
		}
	}
}
Ejemplo n.º 9
0
/* Test comparison for a single instruction. */
static void TryOneInstruction(uint8_t *itext, size_t nbytes) {
  NaClEnumerator pinst; /* for prod validator */
  NaClEnumerator dinst; /* for dfa validator */
  Bool prod_okay, rdfa_okay;

  IncrTried();
  do {
    if (gVerbose) {
      printf("================");
      PrintBytes(stdout, itext, nbytes);
      printf("\n");
    }

    /* Try to parse the sequence of test bytes. */
    InitInst(&pinst, itext, nbytes);
    InitInst(&dinst, itext, nbytes);
    vProd->_parse_inst_fn(&pinst, kTextAddress);
    vDFA->_parse_inst_fn(&dinst, kTextAddress);
    prod_okay = vProd->_maybe_inst_validates_fn(&pinst);
    rdfa_okay = vDFA->_maybe_inst_validates_fn(&dinst);

    if (prod_okay && rdfa_okay) {
      if (vProd->_inst_length_fn(&pinst) ==
          vDFA->_inst_length_fn(&dinst)) {
        /* Both validators see a legal instruction, */
        /* and they agree on critical details.      */
        IncrValid();
      } else {
        DecoderError("LENGTH MISMATCH", &pinst, &dinst, "");
        IncrErrors();
      }
    } else if (prod_okay && !rdfa_okay) {
      /*
       * 32bit production validator by design is unable to distingush a lot of
       * instructions (the ones which work only with memory or only with
       * registers).  To avoid commiting multimegabyte golden file don't count
       * these differences as substantial.  It's not a security problem if we
       * reject some valid x86 instructions and if we'll lose something
       * important hopefully developers will remind us.
       */
      if (NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 &&
          NACL_TARGET_SUBARCH == 32) {
        IncrIgnored();
      } else {
        /* Validators disagree on instruction legality */
        DecoderError("VALIDATORS DISAGREE (prod accepts, RDFA rejects)",
                     &pinst,
                     &dinst,
                     "");
        IncrErrors();
      }
    } else if (!prod_okay && rdfa_okay) {
      /* Validators disagree on instruction legality */
      DecoderError("VALIDATORS DISAGREE (prod rejects, RDFA accepts)",
                   &pinst,
                   &dinst,
                   "");
      IncrErrors();
    } else {
      /* Both validators see an illegal instruction */
      IncrInvalid();
    }

    if (gVerbose) {
      PrintDisassembledInstructionVariants(&pinst, &dinst);
    }
  } while (0);
}
Ejemplo n.º 10
0
/*
 * Method:		Java_jp_co_anaheim_1eng_camellia_MainActivity_testVectors
 */
JNIEXPORT jint JNICALL Java_jp_co_anaheim_1eng_camellia_MainActivity_testVectors (JNIEnv *env, jobject thiz)
{
	//region 128-bit key
	unsigned char k128[10][16] = {
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // K No.001
			{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // K No.002
			{0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F}, // K No.003
			{0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0}, // K No.004
			{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}, // K No.005
			{0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00}, // K No.006
			{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}, // K No.007
			{0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}, // K No.008
			{0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01}, // K No.009
			{0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE}  // K No.010
		};

	//region 192-bit key
	unsigned char k192[10][24] = {
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // K No.001
			{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // K No.002
			{0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F}, // K No.003
			{0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0}, // K No.004
			{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88}, // K No.005
			{0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}, // K No.006
			{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}, // K No.007
			{0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}, // K No.008
			{0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01, 0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01}, // K No.009
			{0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE}  // K No.010
		};

	//region 256-bit key
	unsigned char k256[10][32] = {
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // K No.001
			{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, // K No.002
			{0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F}, // K No.003
			{0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0}, // K No.004
			{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00}, // K No.005
			{0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}, // K No.006
			{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}, // K No.007
			{0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}, // K No.008
			{0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01, 0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE}, // K No.009
			{0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01}  // K No.010
		};

	//region plaintext
	unsigned char p[128][16] = {
			{0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.001
			{0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.002
			{0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.003
			{0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.004
			{0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.005
			{0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.006
			{0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.007
			{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.008
			{0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.009
			{0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.010
			{0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.011
			{0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.012
			{0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.013
			{0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.014
			{0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.015
			{0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.016
			{0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.017
			{0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.018
			{0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.019
			{0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.020
			{0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.021
			{0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.022
			{0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.023
			{0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.024
			{0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.025
			{0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.026
			{0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.027
			{0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.028
			{0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.029
			{0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.030
			{0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.031
			{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.032
			{0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.033
			{0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.034
			{0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.035
			{0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.036
			{0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.037
			{0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.038
			{0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.039
			{0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.040
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.041
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.042
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.043
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.044
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.045
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.046
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.047
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.048
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.049
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.050
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.051
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.052
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.053
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.054
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.055
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.056
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.057
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.058
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.059
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.060
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.061
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.062
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.063
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.064
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.065
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.066
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.067
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.068
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.069
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.070
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.071
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.072
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.073
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.074
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.075
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.076
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.077
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.078
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.079
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.080
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.081
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.082
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.083
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.084
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.085
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.086
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.087
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}, //P No.088
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00}, //P No.089
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00}, //P No.090
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00}, //P No.091
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00}, //P No.092
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}, //P No.093
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}, //P No.094
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00}, //P No.095
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00}, //P No.096
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00}, //P No.097
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00}, //P No.098
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00}, //P No.099
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00}, //P No.100
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00}, //P No.101
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00}, //P No.102
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00}, //P No.103
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}, //P No.104
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00}, //P No.105
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00}, //P No.106
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00}, //P No.107
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00}, //P No.108
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00}, //P No.109
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00}, //P No.110
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00}, //P No.111
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}, //P No.112
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00}, //P No.113
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00}, //P No.114
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00}, //P No.115
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00}, //P No.116
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00}, //P No.117
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00}, //P No.118
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00}, //P No.119
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}, //P No.120
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80}, //P No.121
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40}, //P No.122
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20}, //P No.123
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}, //P No.124
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08}, //P No.125
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04}, //P No.126
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, //P No.127
			{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}  //P No.128
		};

	static KEY_TABLE_TYPE keyTable;
	static unsigned char rawKey[32];
	unsigned char ct_buf[16];
	unsigned char pt_buf[16];

	unsigned char buf[100] = "";

	FILE *fp;
	fp = fopen( "/sdcard/a_camellia.txt", "w" );
	if( fp == NULL ) {
		DebugLogInfo("File cannot open error.");
		return 1;
	}

	fprintf(fp, "Camellia with 128-bit key\n\n");
	int i;
	for(i=0; i<10; i++ ){
		fprintf(fp, "K No.%03d : ", i+1 );
		memset(buf, 0, sizeof(buf));
		PrintBytes(k128[i], 16, buf);
		fprintf(fp, buf);
		fprintf(fp, "\n\n");

		// 拡大鍵領域の初期化
		memset(keyTable, 0, sizeof(keyTable));
		memset(rawKey, 0, sizeof(rawKey));
		// rawKeyの復元
		memcpy(rawKey, k128[i], 128);
		Camellia_Ekeygen(128, rawKey, keyTable);

		int j;
		for (j=0; j<128; j++) {
			fprintf(fp, "P No.%03d : ", j+1 );
			memset(buf, 0, sizeof(buf));
			PrintBytes(p[j], 16, buf);
			fprintf(fp, buf);
			fprintf(fp, "\n");
			/* 暗号化*/
			Camellia_EncryptBlock(128, p[j], keyTable, ct_buf);
			fprintf(fp, "C No.%03d : ", j+1 );
			memset(buf, 0, sizeof(buf));
			PrintBytes(ct_buf, 16, buf);
			fprintf(fp, buf);
			fprintf(fp, "\n\n");
		}
	}

	fprintf(fp, "Camellia with 192-bit key\n\n");
	for(i=0; i<10; i++ ){
		fprintf(fp, "K No.%03d : ", i+1 );
		memset(buf, 0, sizeof(buf));
		PrintBytes(k192[i], 24, buf);
		fprintf(fp, buf);
		fprintf(fp, "\n\n");

		// 拡大鍵領域の初期化
		memset(keyTable, 0, sizeof(keyTable));
		memset(rawKey, 0, sizeof(rawKey));
		// rawKeyの復元
		memcpy(rawKey, k192[i], 192);
		Camellia_Ekeygen(192, rawKey, keyTable);

		int j;
		for (j=0; j<128; j++) {
			fprintf(fp, "P No.%03d : ", j+1 );
			memset(buf, 0, sizeof(buf));
			PrintBytes(p[j], 16, buf);
			fprintf(fp, buf);
			fprintf(fp, "\n");
			/* 暗号化*/
			Camellia_EncryptBlock(192, p[j], keyTable, ct_buf);
			fprintf(fp, "C No.%03d : ", j+1 );
			memset(buf, 0, sizeof(buf));
			PrintBytes(ct_buf, 16, buf);
			fprintf(fp, buf);
			fprintf(fp, "\n\n");
		}
	}

	fprintf(fp, "Camellia with 256-bit key\n\n");
	for(i=0; i<10; i++ ){
		fprintf(fp, "K No.%03d : ", i+1 );
		memset(buf, 0, sizeof(buf));
		PrintBytes(k256[i], 32, buf);
		fprintf(fp, buf);
		fprintf(fp, "\n\n");

		// 拡大鍵領域の初期化
		memset(keyTable, 0, sizeof(keyTable));
		memset(rawKey, 0, sizeof(rawKey));
		// rawKeyの復元
		memcpy(rawKey, k256[i], 256);
		Camellia_Ekeygen(256, rawKey, keyTable);

		int j;
		for (j=0; j<128; j++) {
			fprintf(fp, "P No.%03d : ", j+1 );
			memset(buf, 0, sizeof(buf));
			PrintBytes(p[j], 16, buf);
			fprintf(fp, buf);
			fprintf(fp, "\n");
			/* 暗号化*/
			Camellia_EncryptBlock(256, p[j], keyTable, ct_buf);
			fprintf(fp, "C No.%03d : ", j+1 );
			memset(buf, 0, sizeof(buf));
			PrintBytes(ct_buf, 16, buf);
			fprintf(fp, buf);
			fprintf(fp, "\n\n");
		}
	}

	fflush(fp);
	fclose(fp);
	return 0;
}
Ejemplo n.º 11
0
void PrintTestOther(FILE *f, int Ocsp, int Crl)
{
    PTEID_Status tStatus = {0};
    PTEID_Bytes Application = {0};
    PTEID_Bytes APDU = {0};
    PTEID_Bytes Response = {0};
    PTEID_Bytes FileID = {0};
    PTEID_Bytes Data = {0};
	PTEID_Pins Pins = {0};
	PTEID_Pin Pin = {0};

	PrintTestFunction(f,"PTEID_GetPINs");
	tStatus = PTEID_GetPINs(&Pins);
	PrintStatus(f,"PTEID_GetPINs",&tStatus);

	Pin.pinType   = Pins.pins[0].pinType;
	Pin.id		  = Pins.pins[0].id;
	Pin.usageCode = Pins.pins[0].usageCode;
	Pin.shortUsage = NULL;
	Pin.longUsage  = NULL;

	//PTEID_ReadFile

	Response.length = PTEID_MAX_PICTURE_LEN;
	Response.data = (BYTE *)malloc(Response.length*sizeof(BYTE));
	memset(Response.data,0,Response.length);

	Application.length = 12;
 	Application.data = (unsigned char *)"\xA0\x00\x00\x01\x77\x50\x4B\x43\x53\x2D\x31\x35";
	FileID.length = 2;
    FileID.data = (unsigned char *)"\x50\x38";

 	PrintTestFunction(f,"PTEID_SelectApplication");
    tStatus = PTEID_SelectApplication(&Application);
	PrintStatus(f,"PTEID_SelectApplication",&tStatus);

 	PrintTestFunction(f,"PTEID_ReadFile");
    tStatus = PTEID_ReadFile(&FileID, &Response, &Pin);
	PrintStatus(f,"PTEID_ReadFile",&tStatus);

	PrintBytes(f,"FILE",&Response);

/* DOES NOT WORK WITH MW 2.6
	Response.length = PTEID_MAX_PICTURE_LEN;
	memset(Response.data,0,Response.length);

	Application.length = 12;
	Application.data = (unsigned char *)"\xA0\x00\x00\x01\x77\x49\x64\x46\x69\x6C\x65\x73";
	FileID.length = 2;
    FileID.data = (unsigned char *)"\x40\x35";

 	PrintTestFunction(f,"PTEID_SelectApplication");
    tStatus = PTEID_SelectApplication(&Application);
	PrintStatus(f,"PTEID_SelectApplication",&tStatus);

 	PrintTestFunction(f,"PTEID_ReadFile");
    tStatus = PTEID_ReadFile(&FileID, &Response, &Pin);
	PrintStatus(f,"PTEID_ReadFile",&tStatus);

	PrintBytes(f,"FILE",&Response);
*/

/* DOES NOT WORK WITH MW 2.6
	Response.length = PTEID_MAX_PICTURE_LEN;
	memset(Response.data,0,Response.length);

	FileID.length = 6;
	FileID.data = (unsigned char *)"\x3F\x00\xDF\x01\x40\x35";

 	PrintTestFunction(f,"PTEID_ReadFile");
    tStatus = PTEID_ReadFile(&FileID, &Response, &Pin);
	PrintStatus(f,"PTEID_ReadFile",&tStatus);

	PrintBytes(f,"FILE",&Response);

	Response.length = PTEID_MAX_PICTURE_LEN;
	memset(Response.data,0,Response.length);
*/

/* DOES NOT WORK WITH MW 2.6
	FileID.length = 6;
	FileID.data = (unsigned char *)"\x3F\x00\xDF\x00\x50\x38";

 	PrintTestFunction(f,"PTEID_ReadFile");
    tStatus = PTEID_ReadFile(&FileID, &Response, &Pin);
	PrintStatus(f,"PTEID_ReadFile",&tStatus);

	PrintBytes(f,"FILE",&Response);
*/

	free(Response.data);

	//PTEID_WriteFile
	PrintTestFunction(f,"PTEID_WriteFile");
	PrintComment(f,"THIS FUNCTION DOES NOT WORK PROPERLY WITH MW 2.6");

/* DOES NOT WORK WITH MW 2.6

	FileID.length = 6;
	FileID.data = (unsigned char *)"\x3F\x00\xDF\x01\x40\x31";
	Data.length =6;
	Data.data = "\x5b\x54\x65\x73\x74\x5d";

	PrintTestFunction(f,"PTEID_WriteFile");
	PrintComment(f,"Trying to write into ID file");
	tStatus = PTEID_WriteFile(&FileID,&Data,&Pin);
	PrintStatus(f,"PTEID_WriteFile",&tStatus);

	FileID.length = 6;
	FileID.data = (unsigned char *)"\x3F\x00\xDF\x01\x40\x39";
	Data.length =6;
	Data.data = "\x5b\x54\x65\x73\x74\x5d";

	Response.length = 150;
	Response.data = (BYTE *)malloc(Response.length*sizeof(BYTE));
	memset(Response.data,0,Response.length);

	PrintTestFunction(f,"PTEID_ReadFile");
	PrintComment(f,"Read the Preference file");
	tStatus = PTEID_ReadFile(&FileID,&Response,&Pin);
	PrintStatus(f,"PTEID_ReadFile",&tStatus);

	PrintBytes(f,"FILE",&Response);

	FileID.length = 6;
	FileID.data = (unsigned char *)"\x3F\x00\xDF\x01\x40\x39";
	Data.length =6;
	Data.data = "\x5b\x54\x65\x73\x74\x5d";

	PrintTestFunction(f,"PTEID_WriteFile");
	PrintComment(f,"Write into the Preference file");
	tStatus = PTEID_WriteFile(&FileID,&Data,&Pin);
	PrintStatus(f,"PTEID_WriteFile",&tStatus);

	Response.length = 150;
	memset(Response.data,0,Response.length);

	PrintTestFunction(f,"PTEID_ReadFile");
	PrintComment(f,"Read the preference file to check the data written");
    tStatus = PTEID_ReadFile(&FileID, &Response, &Pin);
	PrintStatus(f,"PTEID_ReadFile",&tStatus);

	PrintBytes(f,"FILE",&Response);

	PrintTestFunction(f,"PTEID_WriteFile");
	PrintComment(f,"Rewrite into the Preference file with initial content");
	tStatus = PTEID_WriteFile(&FileID,&Response,&Pin);
	PrintStatus(f,"PTEID_WriteFile",&tStatus);

	free(Response.data);
*/

	//PTEID_ReadBinary
	PrintTestFunction(f,"PTEID_ReadBinary");
	PrintComment(f,"THIS FUNCTION DOES NOT WORK PROPERLY WITH MW 2.6");

/* DOES NOT WORK WITH MW 2.6
	FileID.length = 6;
	FileID.data = (unsigned char *)"\x3F\x00\xDF\x01\x40\x31";

	Response.length = 128;
	Response.data = (BYTE *)malloc(Response.length*sizeof(BYTE));
	memset(Response.data,0,Response.length);

	PrintTestFunction(f,"PTEID_ReadBinary");
	tStatus = PTEID_ReadBinary(&FileID,64,512,&Response);
	PrintStatus(f,"PTEID_ReadBinary",&tStatus);

	PrintBytes(f,"FILE",&Response);

	free(Response.data);


	Response.length = 512;
	Response.data = (BYTE *)malloc(Response.length*sizeof(BYTE));
	memset(Response.data,0,Response.length);

	PrintTestFunction(f,"PTEID_ReadBinary");
	tStatus = PTEID_ReadBinary(&FileID,64,512,&Response);
	PrintStatus(f,"PTEID_ReadBinary",&tStatus);

	PrintBytes(f,"FILE",&Response);

	free(Response.data);

	Response.length = 64;
	Response.data = (BYTE *)malloc(Response.length*sizeof(BYTE));
	memset(Response.data,0,Response.length);

	PrintTestFunction(f,"PTEID_ReadBinary");
	tStatus = PTEID_ReadBinary(&FileID,64,64,&Response);
	PrintStatus(f,"PTEID_ReadBinary",&tStatus);

	PrintBytes(f,"FILE",&Response);

	free(Response.data);
*/

	//PTEID_BeginTransaction
	PrintTestFunction(f,"PTEID_BeginTransaction");
	tStatus = PTEID_BeginTransaction();
	PrintStatus(f,"PTEID_BeginTransaction",&tStatus);

	PrintTestFunction(f,"PTEID_BeginTransaction");
	tStatus = PTEID_BeginTransaction();
	PrintStatus(f,"PTEID_BeginTransaction",&tStatus);


	//PTEID_SendAPDU
	//Get serial number with to short buffer
	APDU.length = 5;
	APDU.data = (unsigned char *)"\x80\xE4\x00\x00\x0A";

	Response.length = APDU.data[4]+2;
	Response.data = (BYTE *)malloc(Response.length*sizeof(BYTE));
	memset(Response.data,0,Response.length);

	PrintTestFunction(f,"PTEID_SendAPDU");
	tStatus = PTEID_SendAPDU(&APDU,NULL,&Response);
	PrintStatus(f,"PTEID_SendAPDU",&tStatus);

	PrintBytes(f,"RESPONSE",&Response);

	PrintTestFunction(f,"PTEID_SendAPDU");
	tStatus = PTEID_SendAPDU(&APDU,&Pin,&Response);
	PrintStatus(f,"PTEID_SendAPDU",&tStatus);

	PrintBytes(f,"RESPONSE",&Response);

	free(Response.data);

	//Get serial number
	APDU.length = 5;
	APDU.data = (unsigned char *)"\x80\xE4\x00\x00\x1C";

	Response.length = APDU.data[4]+2;
	Response.data = (BYTE *)malloc(Response.length*sizeof(BYTE));
	memset(Response.data,0,Response.length);

	PrintTestFunction(f,"PTEID_SendAPDU");
	tStatus = PTEID_SendAPDU(&APDU,&Pin,&Response);
	PrintStatus(f,"PTEID_SendAPDU",&tStatus);

	PrintBytes(f,"RESPONSE",&Response);

	free(Response.data);

	//PTEID_EndTransaction
	PrintTestFunction(f,"PTEID_EndTransaction");
	tStatus = PTEID_EndTransaction();
	PrintStatus(f,"PTEID_EndTransaction",&tStatus);

	PrintTestFunction(f,"PTEID_EndTransaction");
	tStatus = PTEID_EndTransaction();
	PrintStatus(f,"PTEID_EndTransaction",&tStatus);

	//PTEID_FlushCache
	PrintTestFunction(f,"PTEID_FlushCache");
	tStatus = PTEID_FlushCache();
	PrintStatus(f,"PTEID_FlushCache",&tStatus);
}