Fix warnings.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2024-08-23 13:17:10 +02:00
parent b4487892a2
commit 65fea84df1
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3
11 changed files with 49 additions and 72 deletions

View file

@ -48,7 +48,7 @@ int process_apdu() {
if (is_chaining) {
memmove(apdu.data + (chain_ptr - chain_buf), apdu.data, apdu.nc);
memcpy(apdu.data, chain_buf, chain_ptr - chain_buf);
apdu.nc += chain_ptr - chain_buf;
apdu.nc += (uint16_t)(chain_ptr - chain_buf);
is_chaining = false;
}
}
@ -180,7 +180,7 @@ uint16_t set_res_sw(uint8_t sw1, uint8_t sw2) {
}
#ifndef ENABLE_EMULATION
void apdu_thread() {
void apdu_thread(void) {
card_init_core1();
while (1) {
uint32_t m = 0;

View file

@ -71,12 +71,7 @@ void generic_hash(mbedtls_md_type_t md, const uint8_t *input, size_t len, uint8_
mbedtls_md(mbedtls_md_info_from_type(md), input, len, output);
}
int aes_encrypt(const uint8_t *key,
const uint8_t *iv,
int key_size,
int mode,
uint8_t *data,
int len) {
int aes_encrypt(const uint8_t *key, const uint8_t *iv, uint16_t key_size, int mode, uint8_t *data, uint16_t len) {
mbedtls_aes_context aes;
mbedtls_aes_init(&aes);
uint8_t tmp_iv[IV_SIZE];
@ -95,12 +90,7 @@ int aes_encrypt(const uint8_t *key,
return mbedtls_aes_crypt_cfb128(&aes, MBEDTLS_AES_ENCRYPT, len, &iv_offset, tmp_iv, data, data);
}
int aes_decrypt(const uint8_t *key,
const uint8_t *iv,
int key_size,
int mode,
uint8_t *data,
int len) {
int aes_decrypt(const uint8_t *key, const uint8_t *iv, uint16_t key_size, int mode, uint8_t *data, uint16_t len) {
mbedtls_aes_context aes;
mbedtls_aes_init(&aes);
uint8_t tmp_iv[IV_SIZE];
@ -120,10 +110,10 @@ int aes_decrypt(const uint8_t *key,
return mbedtls_aes_crypt_cfb128(&aes, MBEDTLS_AES_DECRYPT, len, &iv_offset, tmp_iv, data, data);
}
int aes_encrypt_cfb_256(const uint8_t *key, const uint8_t *iv, uint8_t *data, int len) {
int aes_encrypt_cfb_256(const uint8_t *key, const uint8_t *iv, uint8_t *data, uint16_t len) {
return aes_encrypt(key, iv, 256, PICO_KEYS_AES_MODE_CFB, data, len);
}
int aes_decrypt_cfb_256(const uint8_t *key, const uint8_t *iv, uint8_t *data, int len) {
int aes_decrypt_cfb_256(const uint8_t *key, const uint8_t *iv, uint8_t *data, uint16_t len) {
return aes_decrypt(key, iv, 256, PICO_KEYS_AES_MODE_CFB, data, len);
}

View file

@ -42,20 +42,10 @@ extern void double_hash_pin(const uint8_t *pin, uint16_t len, uint8_t output[32]
extern void hash_multi(const uint8_t *input, uint16_t len, uint8_t output[32]);
extern void hash256(const uint8_t *input, size_t len, uint8_t output[32]);
extern void generic_hash(mbedtls_md_type_t md, const uint8_t *input, size_t len, uint8_t *output);
extern int aes_encrypt(const uint8_t *key,
const uint8_t *iv,
int key_size,
int mode,
uint8_t *data,
int len);
extern int aes_decrypt(const uint8_t *key,
const uint8_t *iv,
int key_size,
int mode,
uint8_t *data,
int len);
extern int aes_encrypt_cfb_256(const uint8_t *key, const uint8_t *iv, uint8_t *data, int len);
extern int aes_decrypt_cfb_256(const uint8_t *key, const uint8_t *iv, uint8_t *data, int len);
extern int aes_encrypt(const uint8_t *key, const uint8_t *iv, uint16_t key_size, int mode, uint8_t *data, uint16_t len);
extern int aes_decrypt(const uint8_t *key, const uint8_t *iv, uint16_t key_size, int mode, uint8_t *data, uint16_t len);
extern int aes_encrypt_cfb_256(const uint8_t *key, const uint8_t *iv, uint8_t *data, uint16_t len);
extern int aes_decrypt_cfb_256(const uint8_t *key, const uint8_t *iv, uint8_t *data, uint16_t len);
extern mbedtls_ecp_group_id ec_get_curve_from_prime(const uint8_t *prime, size_t prime_len);
#endif

View file

@ -32,11 +32,13 @@
#include <windows.h>
#include <io.h>
#define O_RDWR _O_RDWR
#define O_CREAT _O_CREAT
#define open _open
#define write _write
#define mode_t unsigned short
#define lseek _lseek
#include "mman.h"
#include <fcntl.h>
#else
#ifdef ESP_PLATFORM
#include "esp_compat.h"
@ -50,14 +52,13 @@ const esp_partition_t *part0;
#include <unistd.h>
#include <sys/mman.h>
#endif
#include <fcntl.h>
#endif
#define FLASH_SECTOR_SIZE 4096
#define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024)
#define XIP_BASE 0
int fd_map = 0;
uint8_t *map = NULL;
#endif
#endif
#include "pico_keys.h"
#include <string.h>
@ -109,9 +110,7 @@ void do_flash() {
//printf("WRITTING %X\n",flash_pages[r].address-XIP_BASE);
uint32_t ints = save_and_disable_interrupts();
flash_range_erase(flash_pages[r].address - XIP_BASE, FLASH_SECTOR_SIZE);
flash_range_program(flash_pages[r].address - XIP_BASE,
flash_pages[r].page,
FLASH_SECTOR_SIZE);
flash_range_program(flash_pages[r].address - XIP_BASE, flash_pages[r].page, FLASH_SECTOR_SIZE);
restore_interrupts(ints);
while (multicore_lockout_end_timeout_us(1000) == false) {
;

View file

@ -283,7 +283,7 @@ void led_blinking_task() {
}
#elif defined(CYW43_WL_GPIO_LED_PIN)
cyw43_arch_gpio_put(led_color, led_state);
#elif ESP_PLATFORM
#elif defined(ESP_PLATFORM)
neopixel_SetPixel(neopixel, &pixel[led_state], 1);
#endif
led_state ^= 1; // toggle

View file

@ -77,6 +77,7 @@ static portMUX_TYPE mutex = portMUX_INITIALIZER_UNLOCKED;
#define CCID_THREAD_TERMINATED 0xffff
#define CCID_ACK_TIMEOUT 0x6600
PACK(
typedef struct {
uint8_t bMessageType;
uint32_t dwLength;
@ -85,7 +86,7 @@ typedef struct {
uint8_t abRFU0;
uint16_t abRFU1;
uint8_t apdu; //Actually it is an array
} __attribute__((__packed__)) ccid_header_t;
}) ccid_header_t;
uint8_t ccid_status = 1;
static uint8_t itf_num;

View file

@ -18,16 +18,9 @@
#ifndef _CTAP_HID_H_
#define _CTAP_HID_H_
#ifdef _MSC_VER // Windows
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long int uint64_t;
#else
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#endif
#ifdef __cplusplus
extern "C" {
@ -47,6 +40,7 @@ extern "C" {
#define TYPE_INIT 0x80 // Initial frame identifier
#define TYPE_CONT 0x00 // Continuation frame identifier
PACK(
typedef struct {
uint32_t cid; // Channel identifier
union {
@ -62,7 +56,7 @@ typedef struct {
uint8_t data[HID_RPT_SIZE - 5]; // Data payload
} cont;
};
} __attribute__((__packed__)) CTAPHID_FRAME;
}) CTAPHID_FRAME;
extern CTAPHID_FRAME *ctap_req, *ctap_resp;
@ -120,10 +114,12 @@ extern CTAPHID_FRAME *ctap_req, *ctap_resp;
#define CAPFLAG_WINK 0x01 // Device supports WINK command
#define CAPFLAG_CBOR 0x04 // Device supports CBOR command
PACK(
typedef struct {
uint8_t nonce[INIT_NONCE_SIZE]; // Client application nonce
} __attribute__((__packed__)) CTAPHID_INIT_REQ;
}) CTAPHID_INIT_REQ;
PACK(
typedef struct {
uint8_t nonce[INIT_NONCE_SIZE]; // Client application nonce
uint32_t cid; // Channel identifier
@ -132,7 +128,7 @@ typedef struct {
uint8_t versionMinor; // Minor version number
uint8_t versionBuild; // Build version number
uint8_t capFlags; // Capabilities flags
} __attribute__((__packed__)) CTAPHID_INIT_RESP;
}) CTAPHID_INIT_RESP;
// CTAPHID_SYNC command defines

View file

@ -37,11 +37,12 @@ uint8_t (*get_version_minor)() = NULL;
static usb_buffer_t hid_rx[ITF_HID_TOTAL] = {0}, hid_tx[ITF_HID_TOTAL] = {0};
PACK(
typedef struct msg_packet {
uint16_t len;
uint16_t current_len;
uint8_t data[CTAP_MAX_PACKET_SIZE];
} __attribute__((__packed__)) msg_packet_t;
}) msg_packet_t;
msg_packet_t msg_packet = { 0 };
@ -247,11 +248,11 @@ void tud_hid_report_complete_cb(uint8_t instance, uint8_t const *report, uint16_
#ifdef ESP_PLATFORM
taskENTER_CRITICAL(&mutex);
#endif
CTAPHID_FRAME *ctap_req = (CTAPHID_FRAME *) report;
CTAPHID_FRAME *req = (CTAPHID_FRAME *) report;
if (last_write_result[instance] == WRITE_PENDING) {
last_write_result[instance] = WRITE_SUCCESS;
if (FRAME_TYPE(ctap_req) == TYPE_INIT) {
if (ctap_req->init.cmd != CTAPHID_KEEPALIVE) {
if (FRAME_TYPE(req) == TYPE_INIT) {
if (req->init.cmd != CTAPHID_KEEPALIVE) {
send_buffer_size[instance] -= MIN(64 - 7, send_buffer_size[instance]);
}
}
@ -260,11 +261,11 @@ void tud_hid_report_complete_cb(uint8_t instance, uint8_t const *report, uint16_
}
}
if (last_write_result[instance] == WRITE_SUCCESS) {
if (FRAME_TYPE(ctap_req) != TYPE_INIT || ctap_req->init.cmd != CTAPHID_KEEPALIVE) {
if (FRAME_TYPE(req) != TYPE_INIT || req->init.cmd != CTAPHID_KEEPALIVE) {
if (send_buffer_size[instance] > 0) {
ctap_resp = (CTAPHID_FRAME *) ((uint8_t *) ctap_resp + 64 - 5);
uint8_t seq = FRAME_TYPE(ctap_req) == TYPE_INIT ? 0 : FRAME_SEQ(ctap_req) + 1;
ctap_resp->cid = ctap_req->cid;
uint8_t seq = FRAME_TYPE(req) == TYPE_INIT ? 0 : FRAME_SEQ(req) + 1;
ctap_resp->cid = req->cid;
ctap_resp->cont.seq = seq;
hid_tx[ITF_HID_CTAP].r_ptr += 64 - 5;
@ -352,7 +353,7 @@ int driver_process_usb_nopacket_hid() {
}
extern const uint8_t fido_aid[], u2f_aid[];
extern void apdu_thread(), cbor_thread();
extern void apdu_thread(void), cbor_thread(void);
int driver_process_usb_packet_hid(uint16_t read) {
int apdu_sent = 0;
@ -552,7 +553,7 @@ int driver_process_usb_packet_hid(uint16_t read) {
msg_packet.len = msg_packet.current_len = 0;
last_packet_time = 0;
if (apdu_sent < 0) {
return ctap_error(-apdu_sent);
return ctap_error((uint8_t)(-apdu_sent));
}
send_keepalive();
}

View file

@ -87,7 +87,9 @@ bool is_busy() {
}
void usb_send_event(uint32_t flag) {
#if !defined(ENABLE_EMULATION)
queue_add_blocking(&usb_to_card_q, &flag);
#endif
if (flag == EV_CMD_AVAILABLE) {
timeout_start();
}
@ -183,16 +185,8 @@ int card_status(uint8_t itf) {
}
}
}
#else
(void) itf;
#endif
return CCID_ERR_FILE_NOT_FOUND;
}
uint8_t *usb_prepare_response(uint8_t itf) {
#ifndef ENABLE_EMULATION
#ifdef USB_ITF_CCID
#endif
return NULL;
#else
return driver_prepare_response_emul(itf);
#endif
}

View file

@ -26,8 +26,7 @@
#include "pico/util/queue.h"
#endif
#include "esp_compat.h"
#include "compat.h"
/* USB thread */
#define EV_CARD_CHANGE 1
@ -108,12 +107,18 @@ extern void driver_exec_finished_ccid(uint8_t itf, uint16_t size_next);
extern void driver_exec_finished_cont_ccid(uint8_t itf, uint16_t size_next, uint16_t offset);
#endif
#define USB_BUFFER_SIZE 2048 // Size of USB buffer
#ifdef ENABLE_EMULATION
extern void driver_exec_finished_emul(uint8_t itf, uint16_t size_next);
extern void driver_exec_finished_cont_emul(uint8_t itf, uint16_t size_next, uint16_t offset);
#endif
#define USB_BUFFER_SIZE 2048 // Size of USB buffer"
PACK(
typedef struct {
uint8_t buffer[USB_BUFFER_SIZE];
uint16_t r_ptr, w_ptr;
} __attribute__((__packed__)) usb_buffer_t;
uint16_t r_ptr;
uint16_t w_ptr;
}) usb_buffer_t;
typedef enum {
WRITE_UNKNOWN = 0,

View file

@ -18,6 +18,7 @@
#ifndef USB_DESCRIPTORS_H_
#define USB_DESCRIPTORS_H_
PACK(
struct ccid_class_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
@ -41,6 +42,6 @@ struct ccid_class_descriptor {
uint16_t wLcdLayout;
uint8_t bPINSupport;
uint8_t bMaxCCIDBusySlots;
} __attribute__((__packed__));
});
#endif /* USB_DESCRIPTORS_H_ */