-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libptateec: manufacturing protection PTA
This abstraction provides TEEC access to stable PTAs present in the OP-TEE upstream tree. The first of these miscellaenous PTAs to be integrated in the library is the iMX Manufacturing Protection [1] for which two functions are provided: - Retrieval of the EC Public Key. - Signature generation. [1] AN13676, i.MX RT1170 Manufacturing Protection Signed-off-by: Jorge Ramirez-Ortiz <[email protected]>
- Loading branch information
Showing
10 changed files
with
401 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
project(ptateec | ||
VERSION 0.1.0 | ||
LANGUAGES C) | ||
|
||
################################################################################ | ||
# Packages | ||
################################################################################ | ||
find_package(Threads REQUIRED) | ||
if(NOT THREADS_FOUND) | ||
message(FATAL_ERROR "Threads not found") | ||
endif() | ||
|
||
include(GNUInstallDirs) | ||
|
||
################################################################################ | ||
# Source files | ||
################################################################################ | ||
set (SRC | ||
src/pta.c | ||
src/pta_imx_manufacturing_protection.c | ||
) | ||
|
||
################################################################################ | ||
# Built library | ||
################################################################################ | ||
add_library (ptateec ${SRC}) | ||
|
||
set_target_properties (ptateec PROPERTIES | ||
VERSION ${PROJECT_VERSION} | ||
SOVERSION ${PROJECT_VERSION_MAJOR} | ||
) | ||
|
||
################################################################################ | ||
# Flags always set | ||
################################################################################ | ||
target_compile_definitions (ptateec | ||
PRIVATE -D_GNU_SOURCE | ||
PRIVATE -DBINARY_PREFIX="LT" | ||
) | ||
|
||
################################################################################ | ||
# Optional flags | ||
################################################################################ | ||
|
||
################################################################################ | ||
# Public and private header and library dependencies | ||
################################################################################ | ||
target_include_directories(ptateec | ||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
$<INSTALL_INTERFACE:include> | ||
PRIVATE src | ||
) | ||
|
||
target_link_libraries (ptateec | ||
PRIVATE pthread | ||
PRIVATE teec | ||
) | ||
|
||
################################################################################ | ||
# Install targets | ||
################################################################################ | ||
install (TARGETS ptateec | ||
DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
) | ||
|
||
add_subdirectory(include) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
include ../flags.mk | ||
include ../config.mk | ||
|
||
OUT_DIR := $(OO)/libptateec | ||
|
||
.PHONY: all libptateec clean | ||
|
||
all: libptateec | ||
install: libptateec | ||
|
||
LIB_NAME := libptateec | ||
MAJOR_VERSION := 0 | ||
MINOR_VERSION := 1 | ||
PATCH_VERSION := 0 | ||
|
||
LIB_MAJOR := $(LIB_NAME).so.$(MAJOR_VERSION) | ||
LIB_MAJ_MIN := $(LIB_NAME).so.$(MAJOR_VERSION).$(MINOR_VERSION) | ||
LIB_MAJ_MIN_PAT := $(LIB_NAME).so.$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION) | ||
LIBPTATEEC_SO_LIBRARY := $(LIB_MAJ_MIN_PAT) | ||
LIBPTATEEC_AR_LIBRARY := $(LIB_NAME).a | ||
|
||
LIBPTATEEC_SRC_DIR := src | ||
|
||
LIBPTATEEC_SRCS = pta.c \ | ||
pta_imx_manufacturing_protection.c | ||
|
||
LIBPTATEEC_INCLUDES = ${CURDIR}/include | ||
LIBPTATEEC_INCLUDES += ${CURDIR}/../public | ||
|
||
LIBPTATEEC_CFLAGS := $(addprefix -I, $(LIBPTATEEC_INCLUDES)) \ | ||
$(CFLAGS) -D_GNU_SOURCE -fPIC | ||
|
||
LIBPTATEEC_LFLAGS := $(LDFLAGS) -L$(OUT_DIR)/../libteec -lteec -lpthread | ||
|
||
LIBPTATEEC_OBJ_DIR := $(OUT_DIR) | ||
LIBPTATEEC_OBJS := $(patsubst %.c,$(LIBPTATEEC_OBJ_DIR)/%.o, $(LIBPTATEEC_SRCS)) | ||
|
||
$(LIBPTATEEC_OBJ_DIR)/%.o: ${LIBPTATEEC_SRC_DIR}/%.c | ||
$(VPREFIX)mkdir -p $(LIBPTATEEC_OBJ_DIR) | ||
@echo " CC $<" | ||
$(VPREFIX)$(CC) $(LIBPTATEEC_CFLAGS) -c $< -o $@ | ||
|
||
libptateec: $(OUT_DIR)/$(LIBPTATEEC_SO_LIBRARY) | ||
|
||
$(OUT_DIR)/$(LIBPTATEEC_SO_LIBRARY): $(LIBPTATEEC_OBJS) | ||
@echo " LINK $@" | ||
$(VPREFIX)$(CC) -shared -Wl,-soname,$(LIB_MAJOR) -o $@ $+ $(LIBPTATEEC_LFLAGS) | ||
@echo "" | ||
|
||
libptateec: $(OUT_DIR)/$(LIBPTATEEC_AR_LIBRARY) | ||
|
||
$(OUT_DIR)/$(LIBPTATEEC_AR_LIBRARY): $(LIBPTATEEC_OBJS) | ||
@echo " AR $@" | ||
$(VPREFIX)$(AR) rcs $@ $+ | ||
|
||
libptateec: | ||
$(VPREFIX)ln -sf $(LIB_MAJ_MIN_PAT) $(OUT_DIR)/$(LIB_MAJ_MIN) | ||
$(VPREFIX)ln -sf $(LIB_MAJ_MIN) $(OUT_DIR)/$(LIB_MAJOR) | ||
$(VPREFIX)ln -sf $(LIB_MAJOR) $(OUT_DIR)/$(LIB_NAME).so | ||
|
||
################################################################################ | ||
# Cleaning up configuration | ||
################################################################################ | ||
clean: | ||
$(RM) $(LIBPTATEEC_OBJS) | ||
$(RM) $(OUT_DIR)/$(LIB_MAJ_MIN_PAT) | ||
$(RM) $(OUT_DIR)/$(LIB_MAJ_MIN) | ||
$(RM) $(OUT_DIR)/$(LIB_MAJOR) | ||
$(RM) $(OUT_DIR)/$(LIBPTATEEC_SO_LIBRARY) | ||
$(RM) $(OUT_DIR)/$(LIBPTATEEC_AR_LIBRARY) | ||
$(call rmdir,$(OUT_DIR)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
project (libptateec-headers C) | ||
|
||
FILE(GLOB INSTALL_HEADERS "*.h") | ||
|
||
add_library(${PROJECT_NAME} INTERFACE) | ||
|
||
install (FILES ${INSTALL_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause */ | ||
/* | ||
* Copyright (c) 2023, Foundries.io | ||
*/ | ||
|
||
#ifndef PTA_TEE_H | ||
#define PTA_TEE_H | ||
|
||
#include <unistd.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* pta_imx_mprotect_get_key() - Retrieves the iMX CAAM Manufacturing Protection | ||
* EC public key. The components x,y are retrieved in RAW format and should | ||
* be converted to DER or PEM as required. | ||
* | ||
* For the 256 bit curve, this will generate two 32 byte components therefore | ||
* requiring at least a 64 byte buffer. | ||
* | ||
* @return TEEC_ERROR_BAD_PARAMETERS Invalid parameters provided on input. | ||
* @return TEEC_ERROR_ACCESS_DENIED Error opening the TEE session. | ||
* @return TEEC_ERROR_GENERIC Error unspecified. | ||
* @return TEEC_ERROR_SHORT_BUFFER Error small buffer provided. | ||
* @return TEEC_SUCCESS On success. | ||
* | ||
*/ | ||
TEEC_Result pta_imx_mprotect_get_key(char *key, size_t *len); | ||
|
||
/** | ||
* pta_imx_mprotect_sign() - Signs a message using the Manufacturing Protection | ||
* EC private key. | ||
* | ||
* This function takes message data as input and outputs a signature over a | ||
* message composed of the content of the MPMR, followed by the input-data | ||
* message. | ||
* | ||
* @return TEEC_ERROR_BAD_PARAMETERS Invalid parameters provided on input. | ||
* @return TEEC_ERROR_ACCESS_DENIED Error opening the TEE session. | ||
* @return TEEC_ERROR_GENERIC Error unspecified. | ||
* @return TEEC_ERROR_SHORT_BUFFER Error small buffer provided. | ||
* @return TEEC_SUCCESS On success. | ||
* | ||
*/ | ||
TEEC_Result pta_imx_mprotect_sign(char *message, size_t mlen, char *signature, | ||
size_t *slen, char *mpmr, size_t *len); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /*PTA_TEE_H*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
/* | ||
* Copyright (c) 2023, Foundries.io Ltd | ||
*/ | ||
|
||
#ifndef BINARY_PREFIX | ||
#define BINARY_PREFIX "ptateec" | ||
#endif | ||
|
||
#include "pta.h" | ||
|
||
bool pta_open_session(struct ta_context *ctx) | ||
{ | ||
TEEC_Result res = TEEC_SUCCESS; | ||
|
||
if (pthread_mutex_lock(&ctx->lock)) | ||
return false; | ||
|
||
if (!ctx->open) { | ||
res = TEEC_InitializeContext(NULL, &ctx->context); | ||
if (!res) { | ||
res = TEEC_OpenSession(&ctx->context, &ctx->session, | ||
&ctx->uuid, TEEC_LOGIN_PUBLIC, | ||
NULL, NULL, NULL); | ||
if (!res) | ||
ctx->open = true; | ||
} | ||
} | ||
|
||
return !pthread_mutex_unlock(&ctx->lock) && !res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause */ | ||
/* | ||
* Copyright (c) 2023, Foundries.io Ltd | ||
*/ | ||
#ifndef PTA_H | ||
#define PTA_H | ||
|
||
#include <errno.h> | ||
#include <inttypes.h> | ||
#include <pthread.h> | ||
#include <pta_tee.h> | ||
#include <signal.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/types.h> | ||
#include <tee_client_api.h> | ||
#include <teec_trace.h> | ||
|
||
struct ta_context { | ||
pthread_mutex_t lock; | ||
TEEC_Context context; | ||
TEEC_Session session; | ||
TEEC_UUID uuid; | ||
bool open; | ||
}; | ||
|
||
bool pta_open_session(struct ta_context *ctx); | ||
|
||
#endif |
Oops, something went wrong.