| name | embedded-crypto |
| description | Embedded cryptographic operations and secure element integration. Expert skill for hardware crypto accelerators, secure key storage, TrustZone configuration, and side-channel attack mitigation. |
| allowed-tools | Read, Grep, Write, Edit, Bash, Glob, WebFetch, WebSearch |
| graph | {"domains":["domain:embedded-systems"],"specializations":["specialization:embedded-systems"],"skillAreas":["skill-area:rtos-programming","skill-area:firmware-development"],"roles":["role:embedded-engineer"]} |
Embedded Cryptographic Operations Skill
Expert skill for cryptographic operations in embedded systems. Provides expertise in hardware crypto accelerators, secure key storage, TrustZone configuration, and security best practices.
Overview
The Embedded Crypto skill enables secure cryptographic implementation in embedded systems:
- Hardware crypto accelerator usage
- AES/SHA/ECC implementation
- Secure key storage configuration
- TrustZone configuration (Cortex-M33/M55)
- Secure boot chain implementation
- Certificate management
- Random number generation (TRNG)
- Side-channel attack mitigation
Capabilities
1. Hardware Crypto Accelerator Integration
Leverage hardware acceleration for cryptographic operations:
crypto_status_t crypto_hw_init(void)
{
RCC->AHB2ENR |= RCC_AHB2ENR_CRYPTEN;
CRYP->CR = CRYP_CR_ALGODIR | CRYP_CR_ALGOMODE_AES_CBC;
CRYP->CR |= CRYP_CR_CRYPEN;
return CRYPTO_OK;
}
crypto_status_t crypto_aes128_cbc_encrypt(
const uint8_t key[16],
const uint8_t iv[16],
const uint8_t *plaintext,
uint8_t *ciphertext,
size_t length
);
2. Secure Key Storage
Configure secure key storage mechanisms:
typedef enum {
KEY_STORAGE_RAM,
KEY_STORAGE_OTP,
KEY_STORAGE_SECURE_FLASH,
KEY_STORAGE_TRUSTZONE,
KEY_STORAGE_HSM,
} key_storage_t;
typedef struct {
uint32_t id;
key_storage_t location;
uint32_t algorithm;
uint16_t bits;
uint32_t usage;
uint32_t lifetime;
uint8_t exportable;
} key_attributes_t;
crypto_status_t secure_key_import(
const key_attributes_t *attributes,
const uint8_t *data,
size_t length,
uint32_t *key_id
);
3. TrustZone Configuration (ARMv8-M)
Configure TrustZone for secure/non-secure separation:
void sau_configure(void)
{
SAU->RNR = 0;
SAU->RBAR = 0x00020000U;
SAU->RLAR = 0x0007FFFFU | SAU_RLAR_ENABLE_Msk;
SAU->RNR = 1;
SAU->RBAR = 0x20008000U;
SAU->RLAR = 0x2001FFFFU | SAU_RLAR_ENABLE_Msk;
SAU->RNR = 2;
SAU->RBAR = 0x0001F000U;
SAU->RLAR = 0x0001FFFFU | SAU_RLAR_NSC_Msk | SAU_RLAR_ENABLE_Msk;
SAU->CTRL = SAU_CTRL_ENABLE_Msk;
}
__attribute__((cmse_nonsecure_entry))
int32_t secure_encrypt(uint8_t *data, size_t length)
{
if (cmse_check_address_range(data, length, CMSE_AU_NONSECURE) == NULL) {
return CRYPTO_ERR_INVALID_PARAM;
}
return crypto_aes128_encrypt_internal(data, length);
}
4. True Random Number Generation
Implement secure random number generation:
crypto_status_t trng_init(void)
{
RCC->AHB2ENR |= RCC_AHB2ENR_RNGEN;
RNG->CR |= RNG_CR_CED;
RNG->CR |= RNG_CR_RNG_CONFIG3;
RNG->CR |= RNG_CR_RNGEN;
if (!trng_health_test()) {
return CRYPTO_ERR_HEALTH_TEST;
}
return CRYPTO_OK;
}
crypto_status_t trng_generate(uint8_t *output, size_t length);
5. Certificate Management
Handle X.509 certificates for device identity:
typedef struct {
uint8_t *device_cert;
size_t device_cert_len;
uint8_t *intermediate_cert;
size_t intermediate_cert_len;
uint8_t *root_cert;
size_t root_cert_len;
} cert_chain_t;
crypto_status_t cert_verify_chain(
const cert_chain_t *chain,
const cert_store_t *trusted
);
crypto_status_t cert_get_public_key(
const uint8_t *cert,
size_t cert_len,
public_key_t *pubkey
);
6. Side-Channel Attack Mitigation
Implement countermeasures against side-channel attacks:
int crypto_compare_constant_time(
const uint8_t *a,
const uint8_t *b,
size_t length
)
{
uint8_t result = 0;
for (size_t i = 0; i < length; i++) {
result |= a[i] ^ b[i];
}
return result;
}
typedef struct {
uint8_t key_masked[16];
uint8_t mask[16];
uint8_t state_mask[16];
} aes_masked_ctx_t;
crypto_status_t aes_masked_init(
aes_masked_ctx_t *ctx,
const uint8_t key[16]
)
{
trng_generate(ctx->mask, 16);
for (int i = 0; i < 16; i++) {
ctx->key_masked[i] = key[i] ^ ctx->mask[i];
}
return CRYPTO_OK;
}
Process Integration
This skill integrates with the following processes:
| Process | Integration Point |
|---|
secure-boot-implementation.js | Crypto verification and signing |
functional-safety-certification.js | Security certification aspects |
ota-firmware-update.js | Update encryption and signing |
Workflow
1. Security Requirements Analysis
## Security Requirements Checklist
- [ ] Identify assets to protect (keys, data, code)
- [ ] Determine threat model (local, network, physical)
- [ ] Select appropriate algorithms (AES-128/256, ECC P-256)
- [ ] Define key management strategy
- [ ] Plan for side-channel resistance
- [ ] Identify certification requirements (PSA, SESIP, CC)
2. Hardware Capability Assessment
grep -i "crypto\|aes\|sha\|rng" device_datasheet.pdf
arm-none-eabi-gcc -mcpu=cortex-m33 -print-multi-lib | grep cmse
3. Implementation
crypto_hw_init();
trng_init();
key_attributes_t attr = {
.algorithm = KEY_ALG_AES,
.bits = 128,
.usage = KEY_USAGE_ENCRYPT | KEY_USAGE_DECRYPT,
.location = KEY_STORAGE_TRUSTZONE
};
secure_key_import(&attr, device_key, 16, &key_id);
sau_configure();
4. Security Testing
cppcheck --enable=security src/crypto/
python tools/timing_analysis.py build/firmware.elf
python tools/rng_test_suite.py
Output Schema
{
"cryptoCapabilities": {
"hardware": {
"aes": true,
"sha": true,
"ecc": false,
"trng": true
},
"trustzone": true,
"secureElement": false
},
"keyManagement": {
"storageLocations": ["otp", "trustzone"],
"algorithms": ["aes-128-gcm", "ecdsa-p256"],
"keyCount"
Security Best Practices
Key Management
- Never store keys in plaintext in flash
- Use OTP fuses for root keys
- Implement key derivation for session keys
- Zeroize keys after use
Algorithm Selection
- Use AES-GCM for authenticated encryption
- Use ECDSA P-256 for signatures
- Use SHA-256 minimum for hashing
- Avoid deprecated algorithms (DES, MD5, SHA-1)
Implementation
- Use vetted crypto libraries (mbedTLS, wolfSSL)
- Enable hardware acceleration when available
- Implement constant-time operations
- Clear sensitive data from memory
Testing
- Verify TRNG output quality
- Test for timing vulnerabilities
- Validate certificate handling
- Audit crypto configurations
References
See Also
secure-boot-implementation.js - Secure boot process
ota-firmware-update.js - Secure updates
- SK-015: OTA Update skill
- AG-005: Embedded Security Expert agent