Ejemplo n.º 1
0
void EncryptionTask()
{

uint8_t i, data[32], len;

  while(1) {
	
   nrk_led_toggle(ORANGE_LED);
   
   /* 16-byte AES key */
   uint8_t key[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};  
   /* 32-byte string is used as example plaintext data */
   sprintf(data, "This string is used as an input");
   len = 32;

   /* Set AES encryption key
   ** (must be 16 bytes) */
   aes_setkey(key);
   
   printf("key hex (16B):   ");
   for(i=0; i<16; i++)
      printf("%x ", key[i]);
   printf("\r\n");   
   printf("plaintext (%dB): \"%s\"\r\n", len, data);
   printf("plaintext hex:   ");
   for(i=0; i<len; i++)
      printf("%x ", data[i]);
   printf("\r\n");
  
   /* Encrypt data (len must be
   ** a multiple of 16 bytes) */
   aes_encrypt(data, len);
   
   printf("\t\t\t\t...encrypt...\r\n");
   printf("cyphertext hex:  ");
   for(i=0; i<len; i++)
      printf("%x ", data[i]);
   printf("\r\n");
   
   /* Decrypt data (len must be
   ** a multiple of 16 bytes) */
   aes_decrypt(data, len);
   
   printf("\t\t\t\t...decrypt...\r\n");
   printf("plaintext hex:   ");
   for(i=0; i<len; i++)
      printf("%x ", data[i]);
   printf("\r\n\r\n\r\n");


   nrk_wait_until_next_period();

	}
}
int aes_cypher(void *out, const void *in, uint32_t size, const void *iv,
               const void *key, uint32_t keysize, int mode, int encrypt)
{
  int ret = OK;

  if ((size & (AES_BLOCK_SIZE-1)) != 0)
    {
      return -EINVAL;
    }

  if (keysize != 16)
    {
      return -EINVAL;
    }

  ret = sem_wait(&aes_lock);
  if (ret < 0)
    {
      return ret;
    }

  /* AES must be disabled before changing mode, key or IV. */

  aes_enable(false);
  ret = aes_setup_cr(mode, encrypt);
  if (ret < 0)
    {
      goto out;
    }

  aes_setkey(key, keysize);
  if (iv)
    {
      aes_setiv(iv);
    }

  aes_enable(true);
  while (size)
    {
      aes_encryptblock(out, in);
      out = (uint8_t *)out + AES_BLOCK_SIZE;
      in  = (uint8_t *)in  + AES_BLOCK_SIZE;
      size -= AES_BLOCK_SIZE;
    }

  aes_enable(false);

out:
  sem_post(&aes_lock);
  return ret;
}
Ejemplo n.º 3
0
void passchk (void) {
    char test1[100] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", test2[100] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
         enc1[100], enc2[100], *p = getpass ("\nPassword verification:");

    memset (enc1, 0, 100);
    memset (enc2, 0, 100);

    security_through_obscurity (1);
    encode64 (test1, enc1, strlen (test1));
    security_through_obscurity (0);
    aes_setkey (p);
    encode64 (test2, enc2, strlen (test2));

    if (strcmp (enc1, enc2)) {
        fprintf (stderr, "Sorry, passwords do not match.\n");
        fprintf (stderr, "1 %s\n2 %s\n", enc1, enc2);
        exit (0);
    }
}
Ejemplo n.º 4
0
static int aes_generic_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
                              unsigned int keylen)
{
   return aes_setkey(tfm, key, keylen);
}