aceleração em hardware para openssl em sistemas embarcados: introdução e conceitos básicos
DESCRIPTION
-> Introdução - aceleração de hardware para OpenSSL em sistemas embarcados. 1) Sistema embarcados. 2) Aceleradores de hardware 3) SSL - OpenSSL 4) Linux 5) Acelerando 6) IPSec, DPI e segurança sistemica 7) Conclusões 8) Referências A) Referência de chamadas de código para cifrador AES.TRANSCRIPT
Implementação de OpenSSL para
Sistemas Embarcados com Linux:
Aceleradores de Hardware
Bruno Castelucci RA 152503
IA012A:2014 1S Prof.: Marco Aurélio Amaral Henriques
Agenda • Sistemas Embarcados
– Aceleradores de hardware de segurança. • Criptografia/Hash/RNG
– Clientes – Servidores
• SSL – OpenSSL
• Acelerando • Conclusões
– IPSec – DPI – Segurança
• Referências
Sistemas Embarcados
• Sistema microprocessado
• Com função específica
• Inserido em um sistema maior
• Motivos:
– Menor custo / energia / tamanho
– Maior segurança / performance
• Substituidos por PCs?
Aceleradores de Hardware de Segurança
Complexidade PK 1024-2048-bit (NIST)
Uso de Criptografia
Tempo
Aceleradores de Hardware de Segurança
• Motivações
– Velocidade (vs SW)
– Custo
– Energia
– Segurança (*)
• Tipos
– Flexíveis
– FPGA
– Programáveis.
– Maior custo.
– Específicos
– Funções definidas.
– Menor consumo.
Complexidade PK 1024-2048-bit (NIST)
Uso de Criptografia
Tempo
Ganho de Performance
Aceleradores - Clientes
• Tipos: – AES, DES – SHA, MD5 – RNG – RSA, ECC
• Serializados • Presentes em:
– Microntroladores – Smart Cards – Processadores
• Consumo • Industrial
CHA Units:
PKEU — Public Key Execution RNGU — Random Number Generator DEU — Data Encryption Standard AESU — Advanced Encryption Standard MDEU — Message Digest Execution Execution CRCU — Cyclical Redundancy Check
Aceleradores - Servidores
• Tipos:
– AES, DES (~40Gbps)
– SHA, MD5 (~40Gbps)
– RSA, ECC (~25K RSA/s)
– RNG
• Paralelizados
• Presentes em:
– Sistemas de Telecom
*Como gerenciar a entrada
desta quantiade de dados?
Job Queue Controller
Descriptor Controllers
Queue Interface
Job Ring I/F
CHAs
Controlador – Registradores (AES)
* SSL?
SSL -> TLS
• Transport Layer Security (TLS).
– Secure Sockets Layer (SSL).
• Protocolo criptográfico .
• Prove segurança na internet.
• Geralmente implementado em software.
• Secure Shell (SSH).
Tráfego Padrão SSL
• Carregamento Certificados.
• Troca de chaves.
• Troca de dados.
Change Cipher: {0x00,0x0A} TLS_RSA_WITH_3DES_EDE_CBC_SHA {0x00,0x39} TLS_DHE_RSA_WITH_AES_256_CBC_SHA {0xC0,0x24} TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
Pacote TLS
OpenSSL
• SSL/TLS implementada como uma lib no OpenSSL.
– Lib mais popular em sistemas Linux.
– Subcomponentes da OpenSSL:
• Lib de protocolos SSL
• Lib Crypto
• Gerenciamento de certificados
• Download código fonte: www.openssl.org
OpenSSL -Comandos Obter uma lista de comandos no OpenSSL:
$ openssl help
• ca - Gerencia certificados.
• dgst - Calcula hashes.
• enc - (Des)criptografa usando algoritmos de chave simétrica.
• genrsa - Gera par de chaves assimétricas RSA.
• passwd - Calcula Hash de senha.
• rand - Gera números pseudo aleatórios.
• rsautl - (Des)criptografa, assina e verifica dados no formato RSA.
• speed – Mede a performance local.
• s_client – Implementa um cliente TLS/SSL simples.
• s_server – Implementa um servidor TLS/SSL simples.
OpenSSL - Exemplos
$ openssl dgst -sha1 filename
$ openssl dgst -sha1 -sign mykey.pem -out filename.sha1 filename.txt
$ openssl enc -aes-256-cbc -salt -in input.txt -out output.enc
$ openssl enc -d -aes-256-cbc -in input.enc -out output.txt
$ openssl genrsa -out mykey.pem 1024
$ openssl rand -base64 128
Diagrama
Diagrama
* Drivers, Registradores.
Sistema GNU/Linux
OpenSSL
SEC Driver
Acelerador
Browser ESPAÇO DE USUÁRIO
KERNEL
SISTEMA GNU/LINUX
OpenSSL no Linux
Aplicação
OpenSSL
Cryptodev
CryptoAPI
Driver SEC
/dev/crypto
Hardware
Inicializa o hardware, implementa a CryptoAPI utilizando o hardware,
Define Device Tree
Registra /dev/crypto, implementa ioctl, chama CryptoAPI.
Registra função na CrytoAPI, faz ioctl no /dev/crypto
Chama funções do OpenSSL
ablkcipher_encrypt (...)
SET_REG(AES_SC, 0x1234)
ioctl(/dev/crypto, AES_blk_encrypt)
openssl enc -aes-256-cbc
Linux Drivers
• Específicos: – Device Tree: Adiciona o acelerador (dts).
– SEC Driver: Conecta o driver específico (registradores) com a device tree. • Implementa a Cryto API: ablkcipher_encrypt (…)
• Providos: – Cryptodev: registra dispositivo /dev/crypto.
• Implementa o ioctl(…) do dispositivo.
• Chama ablkcipher_encrypt (…)
– OpenSSL: registra a função ablkcipher_encrypt. • Chama ioctl no /dev/crypto.
IP Sec • IPSec está na camada de rede.
– SSL entre aplicação e transporte.
• IPSec mais pode facilmente ser gerenciado pelo hardware.
• Deep Packet Inspection.
*Pergunta Inicio
Inspeção de Pacotes
4x PCIe
10x GB Eth
Analisa e Classifica
Gerenciador de Fila
Acelerador Segurança
DMA
Memória RAM
Core 0 Core 1 Core 2 Core n
Barramento
Pacotes
IPSec AES, DES (~40Gbps) SHA, MD5 (~40Gbps) RSA, ECC (~25K RSA/s)
Segurança de sistemas embarcados
• Tamper
• Memória segura
• Boot
ARM
CPU Boot ROM & HAB Cipher, Hash,
RNG
OCOTP
(Keys, Security Levels)
Secure RAM Tamper
Detect
Secure
Clock
Secure
Debug
External
Memory
Erase
JTAG
SW Alarm
Debug
Alarm
External
Tampers
CSU CSU TZASC
DMA
Master
Peripheral
Slave
CSU
CSU
• TrustZone
• Clock seguro
• Hardware Firewall
Conclusões
• Tráfego seguro na internet aumentando.
– Custo desta implementação em software é inviável.
• Sistemas embarcados provêm menor custo, maior eficiência e segurança.
• Aceleração em hardware paralelizada.
• IPSec pode ser inteiramente gerenciado por Hardware.
– Mesmo nível de segurança.
• Importância da segurança total da solução.
Referências • Security in Embedded Systems: Design Challenges -
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.83.586&rep=rep1&type=pdf
• Hardware Acceleration of OpenSSL Cryptographic Functions for High-Performance Internet Security - http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=5416065
• The Linux Kernel Cryptographic API - http://www.linuxjournal.com/article/6451
• Freescale kernel source tree - http://git.freescale.com/git/cgit.cgi/ppc/sdk/linux.git/tree/
• Cryptodev Webpage - http://cryptodev-linux.org/index.html
• Cryptodev Source Tree - https://github.com/cryptodev-linux/cryptodev-linux
• Transport Layer Security (TLS) Parameters -http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml
• Freescale SDK Documentation - http://www.freescale.com/infocenter/index.jsp?topic=%2FQORIQSDK%2F5009694.html
• OpenSSL documentation - https://www.openssl.org/docs/apps/openssl.html#COMMAND_SUMMARY
• An Introduction to OpenSSL - http://users.dcc.uchile.cl/~pcamacho/tutorial/crypto/openssl/openssl_intro.html
• OpenSSL Command Line How-to - http://www.madboa.com/geek/openssl/
• Crypto Acceleration on OpenBSD - http://www.paeps.cx/pubs/crypto_acceleration/slides.pdf
• P2020 - Security Reference Manual – www.freescale.com
• Wikipedia:
– http://en.wikipedia.org/wiki/Secure_Shell
– http://en.wikipedia.org/wiki/Transport_Layer_Security#TLS_1.2
– http://en.wikipedia.org/wiki/Cipher_suite
BACKUP
Driver SEC /* QorIQ Sec/Crypto 4.0 device tree stub */
linux.git/tree/arch/powerpc/boot/dts/fsl/qoriq-sec4.0-0.dtsi
crypto: crypto@300000 {
compatible = "fsl,sec-v4.0";
fsl,sec-era = <1>;
#address-cells = <1>;
#size-cells = <1>;
reg = <0x300000 0x10000>;
ranges = <0 0x300000 0x10000>;
interrupts = <92 2 0 0>;
sec_jr0: jr@1000 {
compatible = "fsl,sec-v4.0-job-ring";
reg = <0x1000 0x1000>;
interrupts = <88 2 0 0>;
};
...
};
/*CAAM control-plane driver backend
* Controller-level driver, kernel property detection, initialization */
linux.git/tree/drivers/crypto/caam/ctrl.c
static struct of_device_id caam_match[] = {
{ .compatible = "fsl,sec-v4.0", },
{ .compatible = "fsl,sec4.0", },
};
MODULE_DEVICE_TABLE(of, caam_match);
static struct platform_driver caam_driver = {
.driver = {
.name = "caam",
.owner = THIS_MODULE,
.of_match_table = caam_match, },
.probe = caam_probe,
.remove = caam_remove,
};
module_platform_driver(caam_driver);
Driver SEC /* caam - Freescale FSL CAAM support for crypto API */
linux.git/tree/drivers/crypto/caam/caamalg.c
static struct caam_alg_template driver_algs[] = {
...
{
.name = "cbc(aes)",
.driver_name = "cbc-aes-caam",
.blocksize = AES_BLOCK_SIZE,
.type = CRYPTO_ALG_TYPE_ABLKCIPHER,
.template_ablkcipher = {
.setkey = ablkcipher_setkey,
.encrypt = ablkcipher_encrypt,
.decrypt = ablkcipher_decrypt,
.geniv = "eseqiv",
.min_keysize = AES_MIN_KEY_SIZE,
.max_keysize = AES_MAX_KEY_SIZE,
.ivsize = AES_BLOCK_SIZE,
},
.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
}
...
}
static int __init caam_algapi_init(void)
{
...
/* register crypto algorithms the device supports */
t_alg = caam_alg_alloc(ctrldev, &driver_algs[i]);
...
err = crypto_register_alg(&t_alg->crypto_alg);
...
}
static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher, const u8 *key, unsigned int keylen)
static int ablkcipher_encrypt(struct ablkcipher_request *req)
static void init_ablkcipher_job(u32 *sh_desc, dma_addr_t ptr,
struct ablkcipher_edesc *edesc,
struct ablkcipher_request *req,
bool iv_contig)
static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err, void *context)
Criptodev /* Driver for /dev/crypto device (aka CryptoDev) */
cryptodev-linux/ioctl.c
static struct miscdevice cryptodev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "crypto",
.fops = &cryptodev_fops,
.mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH,
};
cryptodev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg_)
{ ...
case COMPAT_CIOCCRYPT:
...
ret = crypto_run(fcr, &kcop);
...
}
int crypto_run(struct fcrypt *fcr, struct kernel_crypt_op *kcop)
{ ...
ret = __crypto_run_std(ses_ptr, &kcop->cop);
...
}
static int __crypto_run_std(struct csession *ses_ptr, struct crypt_op *cop)
{ ...
ret = hash_n_crypt(ses_ptr, cop, &sg, &sg, current_len);
...
)
static int hash_n_crypt(struct csession *ses_ptr, struct crypt_op *cop, struct scatterlist *src_sg, struct scatterlist *dst_sg, uint32_t len)
{ ...
ret = cryptodev_cipher_encrypt(&ses_ptr->cdata, src_sg, dst_sg, len);
...
}
ssize_t cryptodev_cipher_encrypt(struct cipher_data *cdata, const struct scatterlist *src, struct scatterlist *dst, size_t len)
{ ...
ret = crypto_ablkcipher_encrypt(cdata->async.request);
...
}