the freebsd project - bsdcan · crypto acceleration on freebsd philip paeps [email protected] the...

28
Crypto Acceleration on FreeBSD Philip Paeps [email protected] The FreeBSD Project BSDCan 2009 — Ottawa, Canada 8 May 2009

Upload: dangnhu

Post on 04-Sep-2018

238 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Crypto Acceleration on FreeBSD

Philip [email protected]

The FreeBSD Project

BSDCan 2009 — Ottawa, Canada8 May 2009

Page 2: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Outline

1 Background and ContextHistory and PurposeList of ComponentsAdoption in the System

2 Implementation and ArchitectureArchitectural OverviewModes of OperationSoftware Interface

3 Hardware AccelerationHardware AccelerationDrawbacks and Pitfalls

4 Works in ProgressSession-Management LayerImprove ParallelismMore Hardware Support

Philip Paeps Crypto Acceleration on FreeBSD

Page 3: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

History and PurposeList of ComponentsAdoption in the System

Outline

1 Background and ContextHistory and PurposeList of ComponentsAdoption in the System

2 Implementation and ArchitectureArchitectural OverviewModes of OperationSoftware Interface

3 Hardware AccelerationHardware AccelerationDrawbacks and Pitfalls

4 Works in ProgressSession-Management LayerImprove ParallelismMore Hardware Support

Philip Paeps Crypto Acceleration on FreeBSD

Page 4: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

History and PurposeList of ComponentsAdoption in the System

In The Beginning. . .

Developed for OpenBSD by Angelos D. Keromytis

Consistent software and hardware interface

Fairly modular and extendable design

Ported to FreeBSD by Sam Leffler in 2002

Originally particularly intended for IPSEC

Very little of the original code remains

Philip Paeps Crypto Acceleration on FreeBSD

Page 5: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

History and PurposeList of ComponentsAdoption in the System

List of Components

Kernel “library” for crypto operations

Generic software crypto device

Support for acceleration hardware

Interface to userland for acceleration

Philip Paeps Crypto Acceleration on FreeBSD

Page 6: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

History and PurposeList of ComponentsAdoption in the System

Kernel “Library” for Crypto Operations

“OpenSSL of the kernel”

Reduces code duplication like a library

Fairly self-contained and maintainable

Most functionality is in <opencrypto/cryptodev.h>

Philip Paeps Crypto Acceleration on FreeBSD

Page 7: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

History and PurposeList of ComponentsAdoption in the System

Software Crypto Device

Implemented as a “transformation” system

Supports most relevant crypto transformations

MD5, SHA1, Rijndael, Camellia, . . .Very flexible and easy to extend

Behaves exactly like a “hardware” device

Philip Paeps Crypto Acceleration on FreeBSD

Page 8: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

History and PurposeList of ComponentsAdoption in the System

Acceleration Hardware

Crypto acceleration hardware widely available

Currently mostly useful for “slow” system

Framework automatically takes advantage of hardware

Uses software if no hardware is present

Philip Paeps Crypto Acceleration on FreeBSD

Page 9: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

History and PurposeList of ComponentsAdoption in the System

Interface to Userland

As simple as ioctl on /dev/crypto

Asynchronous session-oriented interface

Mainly used by the OpenSSL “cryptodev” ENGINE

Not on by default — some serious drawbacks!

Philip Paeps Crypto Acceleration on FreeBSD

Page 10: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

History and PurposeList of ComponentsAdoption in the System

Consumers in the Kernel

IPSEC

Block devices (GELI)

Wireless (IEEE 802.11)

ZFS

GSSAPI

Philip Paeps Crypto Acceleration on FreeBSD

Page 11: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

History and PurposeList of ComponentsAdoption in the System

OpenSSL Engine

Limited adoption due to default disabled

This is perhaps a good thing

Patches floating around for many applications

Often < 10 lines of code needed

Philip Paeps Crypto Acceleration on FreeBSD

Page 12: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Architectural OverviewModes of OperationSoftware Interface

Outline

1 Background and ContextHistory and PurposeList of ComponentsAdoption in the System

2 Implementation and ArchitectureArchitectural OverviewModes of OperationSoftware Interface

3 Hardware AccelerationHardware AccelerationDrawbacks and Pitfalls

4 Works in ProgressSession-Management LayerImprove ParallelismMore Hardware Support

Philip Paeps Crypto Acceleration on FreeBSD

Page 13: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Architectural OverviewModes of OperationSoftware Interface

Architectural Overview

Philip Paeps Crypto Acceleration on FreeBSD

Page 14: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Architectural OverviewModes of OperationSoftware Interface

Modes of Operation

Session-based mode

Information cached perdriver (perhaps in hardware)

No need to repeatinitialization for everyoperation

Multiple operations can bechained together

Sessionless mode

Used mainly for keyingoperations or hashing

Input and output parameterspassed in with request

No support for multipleoperations

Philip Paeps Crypto Acceleration on FreeBSD

Page 15: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Architectural OverviewModes of OperationSoftware Interface

Asynchronous Interface

Both modes of operation are asynchronous

Consumers are not necessarily processes

Drivers not able to sleep(9)

Callback mechanism for status and errors

Philip Paeps Crypto Acceleration on FreeBSD

Page 16: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Architectural OverviewModes of OperationSoftware Interface

Kernelspace Usage

#include <opencrypto/cryptodev.h>

Initialize session parameters once

Multiple operations can be chained together

Framework takes care of the rest

Philip Paeps Crypto Acceleration on FreeBSD

Page 17: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Hardware AccelerationDrawbacks and Pitfalls

Outline

1 Background and ContextHistory and PurposeList of ComponentsAdoption in the System

2 Implementation and ArchitectureArchitectural OverviewModes of OperationSoftware Interface

3 Hardware AccelerationHardware AccelerationDrawbacks and Pitfalls

4 Works in ProgressSession-Management LayerImprove ParallelismMore Hardware Support

Philip Paeps Crypto Acceleration on FreeBSD

Page 18: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Hardware AccelerationDrawbacks and Pitfalls

Supported Devices

glxsb(4) — AMD Geode

hifn(4) — Hifn

padlock(4) — VIA Padlock

safe(4) — SafeNet

ubsec(4) — Broadcom/Bluesteel

Philip Paeps Crypto Acceleration on FreeBSD

Page 19: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Hardware AccelerationDrawbacks and Pitfalls

Driver-side API

Drivers register algorithms they support with the framework

Callbacks for session management and for dispatching work

Sessions are managed by the drivers

Currently no real “prioritization” support

Mostly compatible with OpenBSD for now

No support for cyphertext stealing (point to Doug)

Philip Paeps Crypto Acceleration on FreeBSD

Page 20: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Hardware AccelerationDrawbacks and Pitfalls

Kernel-side Issues

Sessions are managed by device drivers

No (real) way to migrate sessions

Very minimal support for prioritization

Limited flow-control opportunities

Philip Paeps Crypto Acceleration on FreeBSD

Page 21: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Hardware AccelerationDrawbacks and Pitfalls

Trends in Hardware

Acceleration hardware becoming faster

Moving from slow(ish) PCI bus to integrated

Becoming more and more like co-processors

Philip Paeps Crypto Acceleration on FreeBSD

Page 22: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Hardware AccelerationDrawbacks and Pitfalls

Further Problems in Userland

OpenSSL ENGINEs are “all or nothing”

Context switching often very undesirable

No heuristic for deciding if acceleration makes sense

On a fast machine, software is often fastest

Philip Paeps Crypto Acceleration on FreeBSD

Page 23: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Session-Management LayerImprove ParallelismMore Hardware Support

Outline

1 Background and ContextHistory and PurposeList of ComponentsAdoption in the System

2 Implementation and ArchitectureArchitectural OverviewModes of OperationSoftware Interface

3 Hardware AccelerationHardware AccelerationDrawbacks and Pitfalls

4 Works in ProgressSession-Management LayerImprove ParallelismMore Hardware Support

Philip Paeps Crypto Acceleration on FreeBSD

Page 24: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Session-Management LayerImprove ParallelismMore Hardware Support

Session-Management Layer

Add support for migrating sessions between drivers

Enable load-balancing across multiple devices

Heuristics to determine if software is faster

Tell userspace (OpenSSL) if no hardware is available

Philip Paeps Crypto Acceleration on FreeBSD

Page 25: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Session-Management LayerImprove ParallelismMore Hardware Support

Architectural Overview

Philip Paeps Crypto Acceleration on FreeBSD

Page 26: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Session-Management LayerImprove ParallelismMore Hardware Support

Improve Parallelism

Hardware is evolving towards multiple execution blocks

Provide a method for flow-control towards hardware

Add support to pin sessions to a single CPU

Philip Paeps Crypto Acceleration on FreeBSD

Page 27: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Session-Management LayerImprove ParallelismMore Hardware Support

More Hardware Support

Currently, mostly low-end embedded hardware supported

Some really sexy high-end devices are available

Often a small matter of programming and access to hardware

Philip Paeps Crypto Acceleration on FreeBSD

Page 28: The FreeBSD Project - BSDCan · Crypto Acceleration on FreeBSD Philip Paeps philip@FreeBSD.org The FreeBSD Project BSDCan 2009 | Ottawa, Canada 8 May 2009

Background and ContextImplementation and Architecture

Hardware AccelerationWorks in Progress

Questions/Comments

Questions? Comments?

Philip Paeps Crypto Acceleration on FreeBSD