Skip to content

Commit

Permalink
Initial commit of crypto add-on
Browse files Browse the repository at this point in the history
NOTE: probably better to merge this in pprzlink, seems unnatural here
  • Loading branch information
podhrmic committed Sep 13, 2017
1 parent 0d14426 commit 080d9ea
Show file tree
Hide file tree
Showing 61 changed files with 16,258 additions and 0 deletions.
1 change: 1 addition & 0 deletions conf/airframes/AGGIEAIR/aggieair_minion_rp3_lia.xml
Expand Up @@ -61,6 +61,7 @@ AggieAir RP3 Minion
<module name="nav" type="launcher"/>
<module name="nav" type="skid_landing"/>
<module name="sys_mon"/>
<module name="crypto"/>
<module name="copilot"/>
<module name="extra_dl">
<!-- in order to use uart1 without chibios we need to remap the peripheral-->
Expand Down
22 changes: 22 additions & 0 deletions conf/modules/crypto.xml
@@ -0,0 +1,22 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="crypto" dir="crypto">
<doc>
<description>
GEC module
</description>
</doc>
<header>
<file name="crypto.h"/>
</header>
<makefile target="ap">
<define name="DATALINK_CRYPTO" value="1"/>
<file name="crypto.c"/>
<file name="gec-ke.c"/>
<file name="gec.c"/>
<file name="gcm.c" dir="modules/crypto/aes"/>
<file name="curve25519-donna.c" dir="modules/crypto/curve25519"/>
<file name="ed25519.c" dir="modules/crypto/ed25519"/>
</makefile>
</module>

118 changes: 118 additions & 0 deletions sw/airborne/modules/crypto/aes/aes.h
@@ -0,0 +1,118 @@
/*
---------------------------------------------------------------------------
Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved.
The redistribution and use of this software (with or without changes)
is allowed without the payment of fees or royalties provided that:
source code distributions include the above copyright notice, this
list of conditions and the following disclaimer;
binary distributions include the above copyright notice, this list
of conditions and the following disclaimer in their documentation.
This software is provided 'as is' with no explicit or implied warranties
in respect of its operation, including, but not limited to, correctness
and fitness for purpose.
---------------------------------------------------------------------------
Issue Date: 20/12/2007
This file contains the definitions required to use AES in C. See aesopt.h
for optimisation details.
*/

#ifndef _AES_H
#define _AES_H

// #include <stdlib.h>

/* This include is used to find 8 & 32 bit unsigned integer types */
#include "brg_types.h"

#if defined(__cplusplus)
extern "C"
{
#endif

#define AES_128 /* if a fast 128 bit key scheduler is needed */

/* The following must also be set in assembler files if being used */

#define AES_ENCRYPT /* if support for encryption is needed */
#define AES_DECRYPT /* if support for decryption is needed */
#define AES_REV_DKS /* define to reverse decryption key schedule */
#define AES_MODES

#define AES_BLOCK_SIZE 16 /* the AES block size in bytes */
#define N_COLS 4 /* the number of columns in the state */

/* The key schedule length is 11, 13 or 15 16-byte blocks for 128, */
/* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes */
/* or 44, 52 or 60 32-bit words. */

#if defined( AES_VAR ) || defined( AES_256 )
#define KS_LENGTH 60
#elif defined( AES_192 )
#define KS_LENGTH 52
#else
#define KS_LENGTH 44
#endif

#define AES_RETURN INT_RETURN

/* the character array 'inf' in the following structures is used */
/* to hold AES context information. This AES code uses cx->inf.b[0] */
/* to hold the number of rounds multiplied by 16. The other three */
/* elements can be used by code that implements additional modes */

typedef union
{ uint_32t l;
uint_8t b[4];
} aes_inf;

typedef struct
{ uint_32t ks[KS_LENGTH];
aes_inf inf;
} aes_encrypt_ctx;

typedef struct
{ uint_32t ks[KS_LENGTH];
aes_inf inf;
} aes_decrypt_ctx;

/* This routine must be called before first use if non-static */
/* tables are being used */

AES_RETURN aes_init(void);

/* Key lengths in the range 16 <= key_len <= 32 are given in bytes, */
/* those in the range 128 <= key_len <= 256 are given in bits */

#if defined( AES_ENCRYPT )

AES_RETURN aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1]);
AES_RETURN aes_encrypt(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]);

#endif

#if defined( AES_DECRYPT )

AES_RETURN aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1]);
AES_RETURN aes_decrypt(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]);

#endif

typedef void cbuf_inc(unsigned char *cbuf);

#define aes_ctr_encrypt aes_ctr_crypt
#define aes_ctr_decrypt aes_ctr_crypt

AES_RETURN aes_ctr_crypt(const unsigned char *ibuf, unsigned char *obuf,
int len, unsigned char *cbuf, cbuf_inc ctr_inc, aes_encrypt_ctx cx[1]);


#if defined(__cplusplus)
}
#endif

#endif

0 comments on commit 080d9ea

Please sign in to comment.