pdock 60 test task
This commit is contained in:
73
gomspace/libcsp/include/csp/crypto/csp_hmac.h
Normal file
73
gomspace/libcsp/include/csp/crypto/csp_hmac.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _CSP_HMAC_H_
|
||||
#define _CSP_HMAC_H_
|
||||
|
||||
#include <csp/csp_types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CSP_HMAC_LENGTH 4
|
||||
|
||||
/**
|
||||
* Append HMAC to packet
|
||||
* @param packet Pointer to packet
|
||||
* @param include_header use header in hmac calculation (this will not modify the flags field)
|
||||
* @return 0 on success, negative on failure
|
||||
*/
|
||||
int csp_hmac_append(csp_packet_t * packet, bool include_header);
|
||||
|
||||
/**
|
||||
* Verify HMAC of packet
|
||||
* @param packet Pointer to packet
|
||||
* @param include_header use header in hmac calculation (this will not modify the flags field)
|
||||
* @return 0 on success, negative on failure
|
||||
*/
|
||||
int csp_hmac_verify(csp_packet_t * packet, bool include_header);
|
||||
|
||||
/**
|
||||
* Calculate HMAC on buffer
|
||||
*
|
||||
* This function is used by append/verify but cal also be called separately.
|
||||
* @param key HMAC key
|
||||
* @param keylen HMAC key length
|
||||
* @param data pointer to data
|
||||
* @param datalen lehgth of data
|
||||
* @param hmac output HMAC calculation (CSP_HMAC_LENGTH)
|
||||
* @return 0 on success, negative on failure
|
||||
*/
|
||||
int csp_hmac_memory(const uint8_t * key, uint32_t keylen, const uint8_t * data, uint32_t datalen, uint8_t * hmac);
|
||||
|
||||
/**
|
||||
* Save a copy of the key string for use by the append/verify functions
|
||||
* @param key HMAC key
|
||||
* @param keylen HMAC key length
|
||||
* @return Always returns 0
|
||||
*/
|
||||
int csp_hmac_set_key(char * key, uint32_t keylen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_HMAC_H_
|
81
gomspace/libcsp/include/csp/crypto/csp_sha1.h
Normal file
81
gomspace/libcsp/include/csp/crypto/csp_sha1.h
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _CSP_SHA1_H_
|
||||
#define _CSP_SHA1_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* The SHA1 block and message digest size in bytes */
|
||||
#define SHA1_BLOCKSIZE 64
|
||||
#define SHA1_DIGESTSIZE 20
|
||||
|
||||
/**
|
||||
SHA1 state structure
|
||||
*/
|
||||
typedef struct {
|
||||
//! Internal SHA1 state.
|
||||
uint64_t length;
|
||||
//! Internal SHA1 state.
|
||||
uint32_t state[5];
|
||||
//! Internal SHA1 state.
|
||||
uint32_t curlen;
|
||||
//! Internal SHA1 state.
|
||||
uint8_t buf[SHA1_BLOCKSIZE];
|
||||
} csp_sha1_state;
|
||||
|
||||
/**
|
||||
* Initialize the hash state
|
||||
* @param sha1 The hash state you wish to initialize
|
||||
*/
|
||||
void csp_sha1_init(csp_sha1_state * sha1);
|
||||
|
||||
/**
|
||||
* Process a block of memory though the hash
|
||||
* @param sha1 The hash state
|
||||
* @param in The data to hash
|
||||
* @param inlen The length of the data (octets)
|
||||
*/
|
||||
void csp_sha1_process(csp_sha1_state * sha1, const uint8_t * in, uint32_t inlen);
|
||||
|
||||
/**
|
||||
* Terminate the hash to get the digest
|
||||
* @param sha1 The hash state
|
||||
* @param out [out] The destination of the hash (20 bytes)
|
||||
*/
|
||||
void csp_sha1_done(csp_sha1_state * sha1, uint8_t * out);
|
||||
|
||||
/**
|
||||
* Calculate SHA1 hash of block of memory.
|
||||
* @param msg Pointer to message buffer
|
||||
* @param len Length of message
|
||||
* @param sha1 Pointer to SHA1 output buffer. Must be 20 bytes or more!
|
||||
*/
|
||||
void csp_sha1_memory(const uint8_t * msg, uint32_t len, uint8_t * hash);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_SHA1_H_
|
52
gomspace/libcsp/include/csp/crypto/csp_xtea.h
Normal file
52
gomspace/libcsp/include/csp/crypto/csp_xtea.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _CSP_XTEA_H_
|
||||
#define _CSP_XTEA_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CSP_XTEA_IV_LENGTH 8
|
||||
|
||||
/**
|
||||
* XTEA encrypt byte array
|
||||
* @param plain Pointer to plain text
|
||||
* @param len Length of plain text
|
||||
* @param iv Initialization vector
|
||||
*/
|
||||
int csp_xtea_encrypt(uint8_t * plain, const uint32_t len, uint32_t iv[2]);
|
||||
|
||||
/**
|
||||
* Decrypt XTEA encrypted byte array
|
||||
* @param cipher Pointer to cipher text
|
||||
* @param len Length of plain text
|
||||
* @param iv Initialization vector
|
||||
*/
|
||||
int csp_xtea_decrypt(uint8_t * cipher, const uint32_t len, uint32_t iv[2]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_XTEA_H_
|
Reference in New Issue
Block a user