Skip to content

Commit b42a8b6

Browse files
initial AutoSAR shim layer
1 parent 88f0777 commit b42a8b6

13 files changed

Lines changed: 1840 additions & 0 deletions

File tree

configure.ac

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7932,6 +7932,19 @@ else
79327932
fi
79337933

79347934

7935+
# Support for autosar shim
7936+
AC_ARG_ENABLE([autosar],
7937+
[AS_HELP_STRING([--enable-autosar],[Enable AutoSAR support (default: disabled)])],
7938+
[ ENABLED_AUTOSAR=$enableval ],
7939+
[ ENABLED_AUTOSAR=no ]
7940+
)
7941+
7942+
if test "$ENABLED_AUTOSAR" = "yes"
7943+
then
7944+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_AUTOSAR"
7945+
fi
7946+
7947+
79357948
# Session Export
79367949
AC_ARG_ENABLE([sessionexport],
79377950
[AS_HELP_STRING([--enable-sessionexport],[Enable export and import of sessions (default: disabled)])],
@@ -9177,6 +9190,7 @@ AM_CONDITIONAL([BUILD_DTLS],[test "x$ENABLED_DTLS" = "xyes" || test "x$ENABLED_U
91779190
AM_CONDITIONAL([BUILD_MAXQ10XX],[test "x$ENABLED_MAXQ10XX" = "xyes"])
91789191
AM_CONDITIONAL([BUILD_ARIA],[test "x$ENABLED_ARIA" = "xyes"])
91799192
AM_CONDITIONAL([BUILD_XILINX],[test "x$ENABLED_XILINX" = "xyes"])
9193+
AM_CONDITIONAL([BUILD_AUTOSAR],[test "x$ENABLED_AUTOSAR" = "xyes"])
91809194

91819195
if test "$ENABLED_REPRODUCIBLE_BUILD" != "yes" &&
91829196
(test "$ax_enable_debug" = "yes" ||
@@ -9668,6 +9682,7 @@ echo " * Dual alg cert support: $ENABLED_DUAL_ALG_CERTS"
96689682
echo " * ERR Queues per Thread: $ENABLED_ERRORQUEUEPERTHREAD"
96699683
echo " * rwlock: $ENABLED_RWLOCK"
96709684
echo " * keylog export: $ENABLED_KEYLOG_EXPORT"
9685+
echo " * AutoSAR : $ENABLED_AUTOSAR"
96719686
echo ""
96729687
echo "---"
96739688

wolfcrypt/src/include.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,6 @@ if BUILD_MAXQ10XX
214214
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/maxim/maxq10xx.c
215215
endif
216216
EXTRA_DIST += wolfcrypt/src/port/maxim/README.md
217+
218+
include wolfcrypt/src/port/autosar/include.am
219+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## 1.0 Intro To Using wolfSSL with AutoSAR
2+
3+
This readme covers building and using wolfSSL for AutoSAR applications. Currently AES-CBC and RNG are supported. The version of AutoSAR used for reference was 4.4. Currently there is no asynchronous support.
4+
5+
6+
## 2.0 Building wolfSSL
7+
8+
### 2.1 wolfSSL Library
9+
To enable the use of AutoSAR with wolfSSL use the enable option --enable-autosar. In example “./configure --eanble-autosar”. If building without autotools then the macro WOLFSSL_AUTOSAR should be defined. This is usually defined in a user_settings.h file which gets included to the wolfSSL build when the macro WOLFSSL_USER_SETTINGS is defined.
10+
11+
12+
### 2.2 Key Redirection
13+
By default the next available key with the same key type desired is used. When specific keys are to be used then key input redirection is needed. This is done at compile time with setting specific macros. An example of key redirection would be as follows :
14+
15+
/* set redirection of primary and secondary */
16+
#define REDIRECTION_CONFIG 0x03
17+
18+
/* set primary key to keyId of 1 and element type CRYPTO_KE_CIPHER_KEY */
19+
#define REDIRECTION_IN1_KEYID 1
20+
#define REDIRECTION_IN1_KEYELMID 0x01
21+
22+
23+
/* set secondary key to keyId of 4 and element type CRYPTO_KE_CIPHER_IV */
24+
#define REDIRECTION_IN2_KEYID 4
25+
#define REDIRECTION_IN2_KEYELMID 0x05
26+
27+
28+
## 3.0 example
29+
30+
There is an example test case located at wolfcrypt/src/port/autsar/example.c. After compiling with autotools (./configure --enable-autsar && make) the example can be ran by running the command ./wolfcrypt/src/port/autsar/example.test
31+
32+
## 4.0 API Implemented
33+
34+
- Std_ReturnType Csm_Decrypt(uint32 jobId,
35+
Crypto_OperationModeType mode, const uint8* dataPtr, uint32 dataLength,
36+
uint8* resultPtr, uint32* resultLengthPtr);
37+
- Std_ReturnType Csm_Encrypt(uint32 jobId,
38+
Crypto_OperationModeType mode, const uint8* dataPtr, uint32 dataLength,
39+
uint8* resultPtr, uint32* resultLengthPtr);
40+
- Std_ReturnType Csm_KeyElementSet(uint32 keyId, uint32 keyElementId,
41+
const uint8* keyPtr, uint32 keyLength);
42+
- Std_ReturnType Csm_RandomGenerate( uint32 jobId, uint8* resultPtr,
43+
uint32* resultLengthPtr);
44+
45+
Along with the structures necessary for these API.

wolfcrypt/src/port/autosar/cryif.c

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/* cryif.c
2+
*
3+
* Copyright (C) 2006-2019 wolfSSL Inc.
4+
*
5+
* This file is part of wolfSSL.
6+
*
7+
* wolfSSL is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfSSL is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
*/
21+
22+
/* AutoSAR 4.4 */
23+
/* shim layer for use of wolfSSL crypto driver */
24+
25+
26+
#ifdef HAVE_CONFIG_H
27+
#include <config.h>
28+
#endif
29+
30+
#include <wolfssl/wolfcrypt/settings.h>
31+
#include <wolfssl/wolfcrypt/port/autosar/Csm.h>
32+
#include <wolfssl/wolfcrypt/port/autosar/CryIf.h>
33+
#include <wolfssl/wolfcrypt/port/autosar/Crypto.h>
34+
35+
#ifdef WOLFSSL_AUTOSAR
36+
#ifndef NO_WOLFSSL_AUTOSAR_CRYIF
37+
38+
#include <wolfssl/wolfcrypt/logging.h>
39+
40+
/* initialization function */
41+
void CryIf_Init(const CryIf_ConfigType* in)
42+
{
43+
(void)in;
44+
Crypto_Init(NULL);
45+
}
46+
47+
48+
void CryIf_GetVersionInfo(Std_VersionInfoType* ver)
49+
{
50+
(void)ver;
51+
}
52+
53+
54+
/* returns E_OK on success */
55+
Std_ReturnType CryIf_ProcessJob(uint32 id, Crypto_JobType* job)
56+
{
57+
WOLFSSL_ENTER("CryIf_ProcessJob");
58+
if (job == NULL) {
59+
return E_NOT_OK;
60+
}
61+
62+
/* only handle synchronous jobs */
63+
if (job->jobPrimitiveInfo->processingType != CRYPTO_PROCESSING_SYNC) {
64+
WOLFSSL_MSG("Crypto Interface only supporting synchronous jobs");
65+
return E_NOT_OK;
66+
}
67+
68+
return Crypto_ProcessJob(id, job);
69+
}
70+
71+
72+
/* not implemented yet since async not supported */
73+
Std_ReturnType CryIf_CancelJob(uint32 id, Crypto_JobType* job)
74+
{
75+
(void)id;
76+
(void)job;
77+
WOLFSSL_STUB("CryIf_CancelJob");
78+
79+
return E_NOT_OK;
80+
}
81+
82+
83+
/* return E_OK on success */
84+
Std_ReturnType CryIf_KeyElementSet(uint32 keyId, uint32 eId, const uint8* key,
85+
uint32 keySz)
86+
{
87+
if (key == NULL || keySz == 0) {
88+
/* report CRYIF_E_PARAM_POINTER to the DET */
89+
return E_NOT_OK;
90+
}
91+
92+
return Crypto_KeyElementSet(keyId, eId, key, keySz);
93+
}
94+
#endif /* NO_WOLFSSL_AUTOSAR_CRYIF */
95+
#endif /* WOLFSSL_AUTOSAR */
96+

0 commit comments

Comments
 (0)