2018-07-30 16:03:10 +00:00
|
|
|
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <esp_err.h>
|
|
|
|
|
2019-01-28 09:48:47 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-07-30 16:03:10 +00:00
|
|
|
/**
|
|
|
|
* @brief Proof Of Possession for authenticating a secure session
|
|
|
|
*/
|
|
|
|
typedef struct protocomm_security_pop {
|
|
|
|
/**
|
|
|
|
* Pointer to buffer containing the proof of possession data
|
|
|
|
*/
|
|
|
|
const uint8_t *data;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Length (in bytes) of the proof of possession data
|
|
|
|
*/
|
|
|
|
uint16_t len;
|
|
|
|
} protocomm_security_pop_t;
|
|
|
|
|
2019-04-12 12:02:38 +00:00
|
|
|
typedef void * protocomm_security_handle_t;
|
|
|
|
|
2018-07-30 16:03:10 +00:00
|
|
|
/**
|
|
|
|
* @brief Protocomm security object structure.
|
|
|
|
*
|
|
|
|
* The member functions are used for implementing secure
|
|
|
|
* protocomm sessions.
|
|
|
|
*
|
|
|
|
* @note This structure should not have any dynamic
|
|
|
|
* members to allow re-entrancy
|
|
|
|
*/
|
|
|
|
typedef struct protocomm_security {
|
|
|
|
/**
|
2019-02-08 09:51:33 +00:00
|
|
|
* Unique version number of security implementation
|
2018-07-30 16:03:10 +00:00
|
|
|
*/
|
|
|
|
int ver;
|
|
|
|
|
|
|
|
/**
|
2019-02-08 09:51:33 +00:00
|
|
|
* Function for initializing/allocating security
|
2018-07-30 16:03:10 +00:00
|
|
|
* infrastructure
|
|
|
|
*/
|
2019-04-12 12:02:38 +00:00
|
|
|
esp_err_t (*init)(protocomm_security_handle_t *handle);
|
2018-07-30 16:03:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function for deallocating security infrastructure
|
|
|
|
*/
|
2019-04-12 12:02:38 +00:00
|
|
|
esp_err_t (*cleanup)(protocomm_security_handle_t handle);
|
2018-07-30 16:03:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts new secure transport session with specified ID
|
|
|
|
*/
|
2019-04-12 12:02:38 +00:00
|
|
|
esp_err_t (*new_transport_session)(protocomm_security_handle_t handle,
|
|
|
|
uint32_t session_id);
|
2018-07-30 16:03:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes a secure transport session with specified ID
|
|
|
|
*/
|
2019-04-12 12:02:38 +00:00
|
|
|
esp_err_t (*close_transport_session)(protocomm_security_handle_t handle,
|
|
|
|
uint32_t session_id);
|
2018-07-30 16:03:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler function for authenticating connection
|
|
|
|
* request and establishing secure session
|
|
|
|
*/
|
2019-04-12 12:02:38 +00:00
|
|
|
esp_err_t (*security_req_handler)(protocomm_security_handle_t handle,
|
|
|
|
const protocomm_security_pop_t *pop,
|
2018-07-30 16:03:10 +00:00
|
|
|
uint32_t session_id,
|
|
|
|
const uint8_t *inbuf, ssize_t inlen,
|
|
|
|
uint8_t **outbuf, ssize_t *outlen,
|
|
|
|
void *priv_data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function which implements the encryption algorithm
|
|
|
|
*/
|
2019-04-12 12:02:38 +00:00
|
|
|
esp_err_t (*encrypt)(protocomm_security_handle_t handle,
|
|
|
|
uint32_t session_id,
|
2018-07-30 16:03:10 +00:00
|
|
|
const uint8_t *inbuf, ssize_t inlen,
|
|
|
|
uint8_t *outbuf, ssize_t *outlen);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function which implements the decryption algorithm
|
|
|
|
*/
|
2019-04-12 12:02:38 +00:00
|
|
|
esp_err_t (*decrypt)(protocomm_security_handle_t handle,
|
|
|
|
uint32_t session_id,
|
2018-07-30 16:03:10 +00:00
|
|
|
const uint8_t *inbuf, ssize_t inlen,
|
|
|
|
uint8_t *outbuf, ssize_t *outlen);
|
|
|
|
} protocomm_security_t;
|
2019-01-28 09:48:47 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|