Exemplo n.º 1
0
int fdt_decode_kbc(const void *blob, int node, struct fdt_kbc *config)
{
	int err;

	err = get_byte_array(blob, node, "keycode-plain",
			config->plain_keycode, FDT_KBC_KEY_COUNT);
	if (!err)
		err = get_byte_array(blob, node, "keycode-shift",
				config->shift_keycode, FDT_KBC_KEY_COUNT);
	if (!err)
		err = get_byte_array(blob, node, "keycode-ctrl",
				config->ctrl_keycode, FDT_KBC_KEY_COUNT);
	if (!err)
		err = get_byte_array(blob, node, "keycode-fn",
				config->fn_keycode, FDT_KBC_KEY_COUNT);
	return err;
}
Exemplo n.º 2
0
hasp_status_t updateConsumption(hasp_handle_t handle, uint8_t tagNo, int isActive, int consumption, uint8_t *random, int *result)
{
  hasp_status_t status;
  unsigned char iobuffer[256];
  VM_IO_BUFFER_T iobuffer_cxt;
  hasp_size_t iolength = 0;
  hasp_u32_t vm_returncode = 0;
  int returnValue = 0; /* false */

  /* initialize arrays and structs */
  memset(iobuffer, 0, sizeof(iobuffer));
  memset(&iobuffer_cxt, 0, sizeof(iobuffer_cxt));

  /* assume that the consumption update fails */
  *result = 0 /* false */;

  /* prepare Aoc API input buffer */
  iobuffer_cxt.cmdBuff = iobuffer;
  iobuffer_cxt.rspBuff = iobuffer;

  put_byte(&iobuffer_cxt, tagNo);
  put_bool(&iobuffer_cxt, isActive);
  put_int(&iobuffer_cxt, consumption);
  put_byte_array(&iobuffer_cxt, random, 8);

  /* iolength = iobuffer_cxt.cmdSize; */
  iolength = sizeof(iobuffer);

  /* invoke the method of VM resource */
  status = hasp_vm_invoke(handle, REDAppMethodId_updateConsumption, iobuffer, &iolength, &vm_returncode);

  if (status != HASP_STATUS_OK)
  {
#ifdef DEBUG
    printf("hasp_vm_invoke(updateConsumption) failed with status: %d\n", status);

    if (status == HASP_VM_METHOD_EXCEPTION_OCCUR)
      printf("exception code is %d, exception info is: %s\n", vm_returncode, iobuffer);
#endif

    return status;
  }

  returnValue = (vm_returncode != 0);

  if (returnValue)
  {
    /* fetch random output parameter */
    get_byte_array(&iobuffer_cxt, random, 8);
  }

  *result = returnValue;

  return status;

} /* updateConsumption */
Exemplo n.º 3
0
hasp_status_t verifyTag(hasp_handle_t handle, uint8_t tagNo, int isActive, const uint8_t *certificate, unsigned char certificateLen, uint8_t *random, int *result)
{
  hasp_status_t status;              /* AoC API return code */
  unsigned char iobuffer[256];       /* AoC API input/output buffer */
  VM_IO_BUFFER_T iobuffer_cxt;       /* AoC API input/output structure */
  hasp_size_t iolength = 0;          /* AoC API input/output buffer length */
  hasp_u32_t vm_returncode = 0;      /* AoC API return value */

  /* initialize arrays and structs */
  memset(iobuffer, 0, sizeof(iobuffer));
  memset(&iobuffer_cxt, 0, sizeof(iobuffer_cxt));

  /* assume that the verification fails */
  *result = 0 /* false */;

  /* prepare Aoc API input buffer */
  iobuffer_cxt.cmdBuff = iobuffer;
  iobuffer_cxt.rspBuff = iobuffer;

  put_byte(&iobuffer_cxt, tagNo);
  put_bool(&iobuffer_cxt, isActive);
  put_byte_array(&iobuffer_cxt, (uint8_t *)certificate, certificateLen);
  put_byte_array(&iobuffer_cxt, random, 8);

  /* iolength = iobuffer_cxt.cmdSize; */
  iolength = sizeof(iobuffer);

  /* invoke the method of VM resource */
  status = hasp_vm_invoke(handle, REDAppMethodId_verifyTag, iobuffer, &iolength, &vm_returncode);
  if (status != HASP_STATUS_OK)
  {
#ifdef DEBUG
    printf("hasp_vm_invoke(verifyTag) failed with status: %d\n", status);

    if (status == HASP_VM_METHOD_EXCEPTION_OCCUR)
      printf("exception code is %d, exception info is: %s\n", vm_returncode, iobuffer);
#endif

    return status;
  }

  if (vm_returncode == 1)
  {
    /* fetch random output parameter */
    get_byte_array(&iobuffer_cxt, random, 8);
  }

  *result = vm_returncode;

  return status;

} /* verifyTag */
Exemplo n.º 4
0
hasp_status_t verifyTag(hasp_handle_t handle, byte tagNo, bool isActive, const byte *certificate, unsigned char certificateLen, byte *random, bool *result)
{
  hasp_status_t status;              /* AoC API return code */
  unsigned char iobuffer[256];       /* AoC API input/output buffer */
  VM_IO_BUFFER_T iobuffer_cxt;       /* AoC API input/output structure */
  hasp_size_t iolength = 0;          /* AoC API input/output buffer length */
  hasp_u32_t vm_returncode = 0;      /* AoC API return value */
  bool returnValue = false;          /* bool return value */

  /* initialize arrays and structs */
  memset(iobuffer, 0, sizeof(iobuffer));
  memset(&iobuffer_cxt, 0, sizeof(iobuffer_cxt));

  /* assume that the verification fails */
  *result = false;

  /* prepare Aoc API input buffer */
  iobuffer_cxt.cmdBuff = iobuffer;
  iobuffer_cxt.rspBuff = iobuffer;

  put_byte(&iobuffer_cxt, tagNo);
  put_bool(&iobuffer_cxt, isActive);
  put_byte_array(&iobuffer_cxt, (byte *)certificate, certificateLen);
  put_byte_array(&iobuffer_cxt, random, 8);

  iolength = iobuffer_cxt.cmdSize;

  /* invoke the method of VM resource */
  status = hasp_vm_invoke(handle, REDAppMethodId_verifyTag, iobuffer, &iolength, &vm_returncode);
  if (status != HASP_STATUS_OK) return status;

  returnValue = (vm_returncode != 0);

  if (returnValue)
  {
    /* fetch random output parameter */
    get_byte_array(&iobuffer_cxt, random, 8);
  }

  *result = returnValue;

  return HASP_STATUS_OK;

} /* verifyTag */
Exemplo n.º 5
0
hasp_status_t updateConsumption(hasp_handle_t handle, byte tagNo, bool isActive, int consumption, byte *random, bool *result)
{
  hasp_status_t status;
  unsigned char iobuffer[256];
  VM_IO_BUFFER_T iobuffer_cxt;
  hasp_size_t iolength = 0;
  hasp_u32_t vm_returncode = 0;
  bool returnValue = false;

  /* initialize arrays and structs */
  memset(iobuffer, 0, sizeof(iobuffer));
  memset(&iobuffer_cxt, 0, sizeof(iobuffer_cxt));

  /* assume that the consumption update fails */
  *result = false;

  /* prepare Aoc API input buffer */
  iobuffer_cxt.cmdBuff = iobuffer;
  iobuffer_cxt.rspBuff = iobuffer;

  put_byte(&iobuffer_cxt, tagNo);
  put_bool(&iobuffer_cxt, isActive);
  put_int(&iobuffer_cxt, consumption);
  put_byte_array(&iobuffer_cxt, random, 8);

  iolength = iobuffer_cxt.cmdSize;

  /* invoke the method of VM resource */
  status = hasp_vm_invoke(handle, REDAppMethodId_updateConsumption, iobuffer, &iolength, &vm_returncode);
  if (status != HASP_STATUS_OK) return status;

  returnValue = (vm_returncode != 0);

  if (returnValue)
  {
    /* fetch random output parameter */
    get_byte_array(&iobuffer_cxt, random, 8);
  }

  *result = returnValue;

  return HASP_STATUS_OK;

} /* updateConsumption */
Exemplo n.º 6
0
int main(int argc, char* argv[]) {
	int h = open(argv[1], O_RDONLY);
	assert(h >= 0);
	mph *mph = load_mph(h);
	close(h);

#define NKEYS 10000000
	h = open(argv[2], O_RDONLY);
	off_t len = lseek(h, 0, SEEK_END);
	lseek(h, 0, SEEK_SET);
	char *data = malloc(len);
	read(h, data, len);
	close(h);
	
	static char *test_buf[NKEYS];
	static int test_len[NKEYS];
	
	char *p = data;
	for(int i = 0; i < NKEYS; i++) {
		while(*p == 0xA || *p == 0xD) p++;
		test_buf[i] = p;
		while(*p != 0xA && *p != 0xD) p++;
		test_len[i] = p - test_buf[i];
	}

	uint64_t total = 0;
	uint64_t u = 0;

	for(int k = 10; k-- != 0; ) {
		int64_t elapsed = - get_system_time();
		for (int i = 0; i < NKEYS; ++i) u += get_byte_array(mph, test_buf[i], test_len[i]);

		elapsed += get_system_time();
		total += elapsed;
		printf("Elapsed: %.3fs; %.3f ns/key\n", elapsed * 1E-6, elapsed * 1000. / NKEYS);
	}
	const volatile int unused = u;
	printf("\nAverage time: %.3fs; %.3f ns/key\n", (total * .1) * 1E-6, (total * .1) * 1000. / NKEYS);
}
Exemplo n.º 7
0
JNIEXPORT void JNICALL Java_com_jtxdriggers_android_ventriloid_VentriloInterface_sendaudio(JNIEnv* env, jobject obj, jbyteArray pcm, jint size, jint rate) {
	jbyte *data = get_byte_array(env, pcm);
	v3_send_audio(V3_AUDIO_SENDTYPE_U2CCUR, rate, data, size, 0);
	release_byte_array(env, pcm, data);
}
Exemplo n.º 8
0
int main(void)
{
   hasp_status_t   status;
   hasp_handle_t   handle;
   hasp_u32_t      vm_returncode = 0;
   hasp_size_t     iolength = 0;
   unsigned char   iobuffer[256] = { 0 };
   char            md5ResultBuffer[64] ={ 0 };
   VM_IO_BUFFER_T  iobuffer_cxt = { 0 }; 
   char *  szmd5str = "this is md5 test";
   const char* scope = 
                        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
                        "<haspscope>"
                        "    <hasp type=\"HASP-HL\" >"
                        "        <license_manager hostname=\"localhost\" />"
                        "    </hasp>"
                        "</haspscope>";
						

   printf("A simple demo program for the Sentinel LDK licensing functions\n");
   printf("Copyright (C) SafeNet, Inc. All rights reserved.\n\n");
   /*
   Access Direct Mode (-4 mode) [TEST-ONLY]
   This mode force the API to always access directly DriverLess keys even if the local LM is recent enough to provide such support.
   To enable this special mode, you must use the undocumented call hasp_login(-4, 0, 0) before any other hasp functions. 
   */
   hasp_login(-4, 0, 0);

   /************************************************************************
   * hasp_login_scope
   *   establishes a context for HASP services
   *   allows specification of several restrictions
   */

   printf("restricting the license to 'local':\n");

   status = hasp_login_scope(HASP_DEFAULT_FID,
                    scope,
                    (hasp_vendor_code_t *)vendor_code,
                    &handle);
   switch (status)
   {
   case HASP_STATUS_OK:
      printf("OK\n");
      break;

   case HASP_FEATURE_NOT_FOUND:
      printf("login to default feature failed\n");
      break;

   case HASP_CONTAINER_NOT_FOUND:
      printf("no sentinel key with vendor code DEMOMA found\n");
      break;

   case HASP_OLD_DRIVER:
      printf("outdated driver version installed\n");
      break;

   case HASP_NO_DRIVER:
      printf("sentinel driver not installed\n");
      break;

   case HASP_INV_VCODE:
      printf("invalid vendor code\n");
      break;

   case HASP_INV_SCOPE:
      printf("invalid XML scope\n");
      break;

   default:
      printf("login to default feature failed with status %d\n", status);
   }
   if (status) {
      exit(-1);
   }


   /************************************************************************
   * Initlialize vm engine 
   */
   //md5 test
   status = hasp_vm_init(handle, VM_RESOURCE_ID);
   if (status) {
      hasp_logout(handle);
      printf("hasp_vm_init failed: %d!\n", status);
      exit(-1);
   }
   else
   {
      printf("hasp_vm_init succeeded!\n");
   }       

   /************************************************************************
   /* Prepare input buffer and to invoke the method of vm resource */
   iobuffer_cxt.cmdBuff = iobuffer;
   iobuffer_cxt.rspBuff = iobuffer;

   put_byte_array(&iobuffer_cxt, szmd5str, strlen(szmd5str));
   put_byte_array(&iobuffer_cxt, md5ResultBuffer, 16);

   iolength = iobuffer_cxt.cmdSize;

   printf("public static void MD5Hash( String p1, byte[] p2 )\n");
   status = hasp_vm_invoke(handle,
      VM_METHOD_ID,//method id      
      iobuffer, 
      &iolength,
      &vm_returncode);
   if (status) {
      hasp_logout(handle);
      printf("hasp_vm_invoke failed: %d!\n", status);
      exit(-1);
   }
   else
   {
      printf("hasp_vm_invoke succeeded!\n");
   }

   get_byte_array(&iobuffer_cxt, md5ResultBuffer, 16);

   dump(md5ResultBuffer, 16, "    ");
   
   /************************************************************************
   /* hasp_vm_close must be called to free vm engine for other processes or threads usage*/
   status = hasp_vm_close(handle);
   if (status) {
      hasp_logout(handle);
      printf("hasp_vm_close failed: %d!\n", status);
      exit(-1);
   }
   else
   {
      printf("hasp_vm_close succeeded!\n");
   }

   /************************************************************************
   * hasp_logout
   *   closes established session and releases allocated memory
   */
   printf("\nlogout                           : ");
   status = hasp_logout(handle);

   switch (status)
   {
   case HASP_STATUS_OK:
      printf("OK\n");
      break;

   case HASP_INV_HND:
      printf("failed: handle not active\n");
      break;

   default:
      printf("failed\n");
   }
   if (status) {
      exit(-1);
   }

   /***********************************************************************/

   wait4key("to close the sample");

   return 0;

} /* main */