2010-11-29 14:15:06 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Amaury Pouly
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2011-10-29 14:22:17 +00:00
|
|
|
#ifndef __CRYPTO_H__
|
|
|
|
#define __CRYPTO_H__
|
|
|
|
|
2010-11-29 14:15:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
2017-01-01 19:48:05 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2010-11-29 14:15:06 +00:00
|
|
|
|
2019-11-10 01:52:08 +00:00
|
|
|
/* crypto.cpp */
|
2011-10-29 14:22:17 +00:00
|
|
|
enum crypto_method_t
|
|
|
|
{
|
|
|
|
CRYPTO_NONE, /* disable */
|
|
|
|
CRYPTO_KEY, /* key */
|
2012-11-26 22:54:44 +00:00
|
|
|
CRYPTO_XOR_KEY, /* XOR key */
|
2011-10-29 14:22:17 +00:00
|
|
|
};
|
|
|
|
|
2012-11-26 22:54:44 +00:00
|
|
|
union xorcrypt_key_t
|
|
|
|
{
|
|
|
|
uint8_t key[64];
|
|
|
|
uint32_t k[16];
|
|
|
|
};
|
|
|
|
|
2011-10-29 14:22:17 +00:00
|
|
|
/* all-in-one function */
|
|
|
|
struct crypto_key_t
|
|
|
|
{
|
|
|
|
enum crypto_method_t method;
|
|
|
|
union
|
|
|
|
{
|
2020-08-08 19:25:50 +00:00
|
|
|
uint8_t key[16];
|
2012-11-26 22:54:44 +00:00
|
|
|
union xorcrypt_key_t xor_key[2];
|
2011-10-29 14:22:17 +00:00
|
|
|
}u;
|
|
|
|
};
|
|
|
|
|
2017-01-01 19:48:05 +00:00
|
|
|
#define CRYPTO_ERROR_SUCCESS 0
|
|
|
|
#define CRYPTO_ERROR_BADSETUP -1
|
2017-01-03 12:56:48 +00:00
|
|
|
#define CRYPTO_ERROR_INVALID_OP -2
|
2017-01-01 19:48:05 +00:00
|
|
|
|
|
|
|
/* parameter can be:
|
|
|
|
* - CRYPTO_KEY: array of 16-bytes (the key)
|
|
|
|
* return 0 on success, <0 on error */
|
|
|
|
int crypto_setup(struct crypto_key_t *key);
|
|
|
|
|
|
|
|
/* return 0 on success, <0 on error */
|
|
|
|
int crypto_apply(
|
2020-08-08 19:25:50 +00:00
|
|
|
uint8_t *in_data, /* Input data */
|
|
|
|
uint8_t *out_data, /* Output data (or NULL) */
|
2011-10-29 14:22:17 +00:00
|
|
|
int nr_blocks, /* Number of blocks (one block=16 bytes) */
|
2020-08-08 19:25:50 +00:00
|
|
|
uint8_t iv[16], /* IV */
|
|
|
|
uint8_t (*out_cbc_mac)[16], /* CBC-MAC of the result (or NULL) */
|
2017-01-01 19:48:05 +00:00
|
|
|
bool encrypt);
|
2011-10-29 14:22:17 +00:00
|
|
|
|
2010-11-29 14:15:06 +00:00
|
|
|
/* crc.c */
|
2020-08-08 19:25:50 +00:00
|
|
|
uint32_t crc(uint8_t *data, int size);
|
|
|
|
uint32_t crc_continue(uint32_t previous_crc, uint8_t *data, int size);
|
2010-11-29 14:15:06 +00:00
|
|
|
|
|
|
|
/* sha1.c */
|
|
|
|
struct sha_1_params_t
|
|
|
|
{
|
2020-08-08 19:25:50 +00:00
|
|
|
uint8_t hash[20]; /* final hash */
|
2017-01-03 15:09:34 +00:00
|
|
|
void *object; /* pointer to CryptoPP::SHA1 object */
|
2010-11-29 14:15:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void sha_1_init(struct sha_1_params_t *params);
|
2020-08-08 19:25:50 +00:00
|
|
|
void sha_1_update(struct sha_1_params_t *params, uint8_t *buffer, int size);
|
2010-11-29 14:15:06 +00:00
|
|
|
void sha_1_finish(struct sha_1_params_t *params);
|
2020-08-08 19:25:50 +00:00
|
|
|
void sha_1_output(struct sha_1_params_t *params, uint8_t *out);
|
2011-10-29 14:22:17 +00:00
|
|
|
|
2012-11-26 22:54:44 +00:00
|
|
|
/* xorcrypt.c */
|
|
|
|
|
|
|
|
// WARNING those functions modifies the keys !!
|
|
|
|
uint32_t xor_encrypt(union xorcrypt_key_t keys[2], void *data, int size);
|
|
|
|
uint32_t xor_decrypt(union xorcrypt_key_t keys[2], void *data, int size);
|
2013-02-16 19:47:07 +00:00
|
|
|
void xor_generate_key(uint32_t laserfuse[3], union xorcrypt_key_t key[2]);
|
2012-11-26 22:54:44 +00:00
|
|
|
|
2017-01-01 19:48:05 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-10-29 14:22:17 +00:00
|
|
|
#endif /* __CRYPTO_H__ */
|