a2p
accept
access
acct
addftinfo
addr2line
adjtime
afmtodit
after
aio_cancel
aio_error
aio_read
aio_return
aio_suspend
aio_waitcomplete
aio_write
alias
aliases
alloc
anvil
append
apply
apropos
ar
array
as
asa
asn1parse
at
atq
atrm
attemptckalloc
attemptckrealloc
authlib
authtest
autopoint
awk
b64decode
b64encode
basename
batch
bc
bdes
bell
bg
bgerror
biff
big5
binary
bind
bindkey
bindtags
bindtextdomain
bio
bitmap
blowfish
bn
bootparams
bootptab
bounce
brandelf
break
breaksw
brk
bsdiff
bsdtar
bsnmpd
bspatch
bthost
btsockstat
buffer
builtin
builtins
bunzip2
button
byacc
bzcat
bzegrep
bzfgrep
bzgrep
bzip2
c2ph
c89
c99
ca
cal
calendar
canvas
cap_mkdb
case
cat
catch
catman
cc
cd
cdcontrol
chdir
checkbutton
checknr
chflags
chfn
chgrp
chio
chkey
chmod
chown
chpass
chroot
chsh
ci
ciphers
ckalloc
ckdist
ckfree
ckrealloc
cksum
cleanup
clear
clipboard
clock
clock_getres
clock_gettime
clock_settime
close
cmp
co
col
colcrt
colldef
colors
colrm
column
comm
command
compile_et
complete
compress
concat
config
connect
console
continue
core
courierlogger
couriertcpd
cp
cpan
cpio
cpp
creat
crl
crontab
crunchgen
crunchide
crypt
crypto
csh
csplit
ctags
ctm
ctm_dequeue
ctm_rmail
ctm_smail
cu
cursor
cursors
cut
cvs
date
dbiprof
dbiproxy
dc
dcgettext
dcngettext
dd
dde
default
defer
deliverquota
des
destroy
devfs
df
dgettext
dgst
dh
dhparam
dialog
diff
diff3
dig
dir
dirent
dirname
dirs
discard
disktab
dngettext
do
domainname
done
dprofpp
dsa
dsaparam
dtmfdecode
du
dup
dup2
eaccess
ec
ecdsa
echo
echotc
ecparam
ed
edit
editrc
ee
egrep
elf
elfdump
elif
else
enc
enc2xs
encoding
end
endif
endsw
engine
enigma
entry
env
envsubst
eof
eqn
err
errno
error
errstr
esac
ethers
euc
eui64
eval
event
evp
ex
exec
execve
exit
expand
export
exports
expr
extattr
extattr_delete_fd
extattr_delete_file
extattr_get_fd
extattr_get_file
extattr_set_fd
extattr_set_file
f77
false
famm
famx
fblocked
fbtab
fc
fchdir
fchflags
fchmod
fchown
fcntl
fconfigure
fcopy
fdescfs
fdformat
fdread
fdwrite
fetch
fg
fgrep
fhopen
fhstat
fhstatfs
fi
file
file2c
fileevent
filename
filetest
find
find2perl
finger
flex
flock
flush
fmt
focus
fold
font
fontedit
for
foreach
fork
format
forward
fpathconf
frame
from
fs
fstab
fstat
fstatfs
fsync
ftp
ftpchroot
ftpusers
ftruncate
futimes
g711conv
gb2312
gb18030
gbk
gcc
gcore
gcov
gdb
gencat
gendsa
genrsa
gensnmptree
getconf
getdents
getdirentries
getdtablesize
getegid
geteuid
getfacl
getfh
getfsstat
getgid
getgroups
getitimer
getlogin
getopt
getopts
getpeername
getpgid
getpgrp
getpid
getppid
getpriority
getresgid
getresuid
getrlimit
getrusage
gets
getsid
getsockname
getsockopt
gettext
gettextize
gettimeofday
gettytab
getuid
glob
global
gmake
goto
gperf
gprof
grab
grep
grid
grn
grodvi
groff
groff_font
groff_out
groff_tmac
grog
grolbp
grolj4
grops
grotty
group
groups
gunzip
gzcat
gzexe
gzip
h2ph
h2xs
hash
hashstat
hd
head
help2man
hesinfo
hexdump
history
host
hostname
hosts
hosts_access
hosts_options
hpftodit
http
hup
i386_get_ioperm
i386_get_ldt
i386_set_ioperm
i386_set_ldt
i386_vm86
iconv
id
ident
idprio
if
ifnames253
ifnames259
image
imapd
incr
indent
indxbib
info
infokey
inode
install
instmodsh
interp
intro
introduction
ioctl
ipcrm
ipcs
ipf
ipftest
ipnat
ippool
ipresend
issetugid
jail
jail_attach
jobid
jobs
join
jot
kbdcontrol
kbdmap
kcon
kdestroy
kdump
kenv
kevent
keycap
keylogin
keylogout
keymap
keysyms
kgdb
kill
killall
killpg
kinit
kldfind
kldfirstmod
kldload
kldnext
kldstat
kldsym
kldunload
klist
kpasswd
kqueue
kse
kse_create
kse_exit
kse_release
kse_switchin
kse_thr_interrupt
kse_wakeup
ktrace
label
labelframe
lam
lappend
last
lastcomm
lastlog
lchflags
lchmod
lchown
ld
ldap
ldapadd
ldapcompare
ldapdelete
ldapmodify
ldapmodrdn
ldappasswd
ldapsearch
ldapwhoami
ldd
leave
less
lesskey
lex
lgetfh
lhash
libnetcfg
library
limit
limits
lindex
link
linprocfs
linsert
lint
lio_listio
list
listbox
listen
lj4_font
lkbib
llength
lmtp
ln
load
loadfont
local
locale
locate
lock
lockf
log
logger
login
logins
logname
logout
look
lookbib
lorder
lower
lp
lpq
lpr
lprm
lptest
lrange
lreplace
ls
lsearch
lseek
lset
lsort
lstat
lsvfs
lutimes
lynx
m4
madvise
magic
mail
maildiracl
maildirkw
maildirmake
mailq
mailx
make
makeinfo
makewhatis
man
manpath
master
mc
mcedit
mcview
md2
md4
md5
mdc2
memory
menu
menubar
menubutton
merge
mesg
message
mincore
minherit
minigzip
mkdep
mkdir
mkfifo
mkimapdcert
mklocale
mknod
mkpop3dcert
mkstr
mktemp
mlock
mlockall
mmap
mmroff
modfind
modfnext
modnext
modstat
moduli
more
motd
mount
mprotect
mptable
msdos
msdosfs
msgattrib
msgcat
msgcmp
msgcomm
msgconv
msgen
msgexec
msgfilter
msgfmt
msggrep
msginit
msgmerge
msgs
msgunfmt
msguniq
mskanji
msql2mysql
msync
mt
munlock
munlockall
munmap
mv
myisamchk
myisamlog
myisampack
mysql
mysqlaccess
mysqladmin
mysqlbinlog
mysqlcheck
mysqld
mysqldump
mysqld_multi
mysqld_safe
mysqlhotcopy
mysqlimport
mysqlshow
mysql_config
mysql_fix_privilege_tables
mysql_zap
namespace
nanosleep
nawk
nc
ncal
ncplist
ncplogin
ncplogout
neqn
netconfig
netgroup
netid
netstat
networks
newaliases
newgrp
nex
nfsstat
nfssvc
ngettext
nice
nl
nm
nmount
nohup
nologin
notify
nroff
nseq
nslookup
ntp_adjtime
ntp_gettime
nvi
nview
objcopy
objdump
objformat
ocsp
od
onintr
open
openssl
opieaccess
opieinfo
opiekey
opiekeys
opiepasswd
option
options
oqmgr
pack
package
packagens
pagesize
palette
pam_auth
panedwindow
parray
passwd
paste
patch
pathchk
pathconf
pawd
pax
pbm
pcre
pcreapi
pcrebuild
pcrecallout
pcrecompat
pcrecpp
pcregrep
pcrematching
pcrepartial
pcrepattern
pcreperform
pcreposix
pcreprecompile
pcresample
pcretest
perl
perl56delta
perl58delta
perl561delta
perl570delta
perl571delta
perl572delta
perl573delta
perl581delta
perl582delta
perl583delta
perl584delta
perl585delta
perl586delta
perl587delta
perl588delta
perl5004delta
perl5005delta
perlaix
perlamiga
perlapi
perlapio
perlapollo
perlartistic
perlbeos
perlbook
perlboot
perlbot
perlbs2000
perlbug
perlcall
perlcc
perlce
perlcheat
perlclib
perlcn
perlcompile
perlcygwin
perldata
perldbmfilter
perldebguts
perldebtut
perldebug
perldelta
perldgux
perldiag
perldoc
perldos
perldsc
perlebcdic
perlembed
perlepoc
perlfaq
perlfaq1
perlfaq2
perlfaq3
perlfaq4
perlfaq5
perlfaq6
perlfaq7
perlfaq8
perlfaq9
perlfilter
perlfork
perlform
perlfreebsd
perlfunc
perlglossary
perlgpl
perlguts
perlhack
perlhist
perlhpux
perlhurd
perlintern
perlintro
perliol
perlipc
perlirix
perlivp
perljp
perlko
perllexwarn
perllinux
perllocale
perllol
perlmachten
perlmacos
perlmacosx
perlmint
perlmod
perlmodinstall
perlmodlib
perlmodstyle
perlmpeix
perlnetware
perlnewmod
perlnumber
perlobj
perlop
perlopenbsd
perlopentut
perlos2
perlos390
perlos400
perlothrtut
perlpacktut
perlplan9
perlpod
perlpodspec
perlport
perlqnx
perlre
perlref
perlreftut
perlrequick
perlreref
perlretut
perlrun
perlsec
perlsolaris
perlstyle
perlsub
perlsyn
perlthrtut
perltie
perltoc
perltodo
perltooc
perltoot
perltrap
perltru64
perltw
perlunicode
perluniintro
perlutil
perluts
perlvar
perlvmesa
perlvms
perlvos
perlwin32
perlxs
perlxstut
perror
pfbtops
pftp
pgrep
phones
photo
pic
pickup
piconv
pid
pipe
pkcs7
pkcs8
pkcs12
pkg_add
pkg_check
pkg_create
pkg_delete
pkg_info
pkg_sign
pkg_version
pkill
pl2pm
place
pod2html
pod2latex
pod2man
pod2text
pod2usage
podchecker
podselect
poll
popd
popup
posix_madvise
postalias
postcat
postconf
postdrop
postfix
postkick
postlock
postlog
postmap
postqueue
postsuper
pr
pread
preadv
printcap
printenv
printf
proc
procfs
profil
protocols
prove
proxymap
ps
psed
psroff
pstruct
ptrace
publickey
pushd
puts
pwd
pwrite
pwritev
qmgr
qmqpd
quota
quotactl
radiobutton
raise
rand
ranlib
rcp
rcs
rcsclean
rcsdiff
rcsfile
rcsfreeze
rcsintro
rcsmerge
read
readelf
readlink
readonly
readv
realpath
reboot
recv
recvfrom
recvmsg
red
ree
refer
regexp
registry
regsub
rehash
remote
rename
repeat
replace
req
reset
resolver
resource
return
rev
revoke
rfcomm_sppd
rfork
rhosts
ripemd
ripemd160
rlog
rlogin
rm
rmd160
rmdir
rpc
rpcgen
rs
rsa
rsautl
rsh
rtld
rtprio
rup
ruptime
rusers
rwall
rwho
s2p
safe
sasl
sasldblistusers2
saslpasswd2
sbrk
scache
scale
scan
sched
sched_getparam
sched_getscheduler
sched_get_priority_max
sched_get_priority_min
sched_rr_get_interval
sched_setparam
sched_setscheduler
sched_yield
scon
scp
script
scrollbar
sdiff
sed
seek
select
selection
semctl
semget
semop
send
sendbug
sendfile
sendmail
sendmsg
sendto
services
sess_id
set
setegid
setenv
seteuid
setfacl
setgid
setgroups
setitimer
setlogin
setpgid
setpgrp
setpriority
setregid
setresgid
setresuid
setreuid
setrlimit
setsid
setsockopt
settc
settimeofday
setty
setuid
setvar
sftp
sh
sha
sha1
sha256
shar
shells
shift
shmat
shmctl
shmdt
shmget
showq
shutdown
sigaction
sigaltstack
sigblock
sigmask
sigpause
sigpending
sigprocmask
sigreturn
sigsetmask
sigstack
sigsuspend
sigvec
sigwait
size
slapadd
slapcat
slapd
slapdn
slapindex
slappasswd
slaptest
sleep
slogin
slurpd
smbutil
smime
smtp
smtpd
socket
socketpair
sockstat
soelim
sort
source
spawn
speed
spinbox
spkac
splain
split
squid
squid_ldap_auth
squid_ldap_group
squid_unix_group
sscop
ssh
sshd_config
ssh_config
stab
startslip
stat
statfs
stop
string
strings
strip
stty
su
subst
sum
suspend
swapoff
swapon
switch
symlink
sync
sysarch
syscall
sysconftool
sysconftoolcheck
systat
s_client
s_server
s_time
tabs
tail
talk
tar
tbl
tclsh
tcltest
tclvars
tcopy
tcpdump
tcpslice
tcsh
tee
tell
telltc
telnet
term
termcap
terminfo
test
texindex
texinfo
text
textdomain
tfmtodit
tftp
then
threads
time
tip
tk
tkerror
tkvars
tkwait
tlsmgr
tmac
top
toplevel
touch
tput
tr
trace
trafshow
trap
troff
true
truncate
truss
tset
tsort
tty
ttys
type
tzfile
ui
ul
ulimit
umask
unalias
uname
uncomplete
uncompress
undelete
unexpand
unhash
unifdef
unifdefall
uniq
units
unknown
unlimit
unlink
unmount
unset
unsetenv
until
unvis
update
uplevel
uptime
upvar
usbhidaction
usbhidctl
users
utf8
utimes
utmp
utrace
uudecode
uuencode
uuidgen
vacation
variable
verify
version
vfork
vgrind
vgrindefs
vi
vidcontrol
vidfont
view
virtual
vis
vt220keys
vwait
w
wait
wait3
wait4
waitpid
wall
wc
wget
what
whatis
where
whereis
which
while
who
whoami
whois
window
winfo
wish
wm
write
writev
wtmp
x509
xargs
xgettext
xmlwf
xstr
xsubpp
yacc
yes
ypcat
ypchfn
ypchpass
ypchsh
ypmatch
yppasswd
ypwhich
yyfix
zcat
zcmp
zdiff
zegrep
zfgrep
zforce
zgrep
zmore
znew
_exit
__syscall
 
FreeBSD/Linux/UNIX General Commands Manual
Hypertext Man Pages
engine
 
engine(3)                           OpenSSL                          engine(3)



NAME
       engine - ENGINE cryptographic module support

SYNOPSIS
        #include 

        ENGINE *ENGINE_get_first(void);
        ENGINE *ENGINE_get_last(void);
        ENGINE *ENGINE_get_next(ENGINE *e);
        ENGINE *ENGINE_get_prev(ENGINE *e);

        int ENGINE_add(ENGINE *e);
        int ENGINE_remove(ENGINE *e);

        ENGINE *ENGINE_by_id(const char *id);

        int ENGINE_init(ENGINE *e);
        int ENGINE_finish(ENGINE *e);

        void ENGINE_load_openssl(void);
        void ENGINE_load_dynamic(void);
        void ENGINE_load_cswift(void);
        void ENGINE_load_chil(void);
        void ENGINE_load_atalla(void);
        void ENGINE_load_nuron(void);
        void ENGINE_load_ubsec(void);
        void ENGINE_load_aep(void);
        void ENGINE_load_sureware(void);
        void ENGINE_load_4758cca(void);
        void ENGINE_load_openbsd_dev_crypto(void);
        void ENGINE_load_builtin_engines(void);

        void ENGINE_cleanup(void);

        ENGINE *ENGINE_get_default_RSA(void);
        ENGINE *ENGINE_get_default_DSA(void);
        ENGINE *ENGINE_get_default_DH(void);
        ENGINE *ENGINE_get_default_RAND(void);
        ENGINE *ENGINE_get_cipher_engine(int nid);
        ENGINE *ENGINE_get_digest_engine(int nid);

        int ENGINE_set_default_RSA(ENGINE *e);
        int ENGINE_set_default_DSA(ENGINE *e);
        int ENGINE_set_default_DH(ENGINE *e);
        int ENGINE_set_default_RAND(ENGINE *e);
        int ENGINE_set_default_ciphers(ENGINE *e);
        int ENGINE_set_default_digests(ENGINE *e);
        int ENGINE_set_default_string(ENGINE *e, const char *list);

        int ENGINE_set_default(ENGINE *e, unsigned int flags);

        unsigned int ENGINE_get_table_flags(void);
        void ENGINE_set_table_flags(unsigned int flags);

        int ENGINE_register_RSA(ENGINE *e);
        void ENGINE_unregister_RSA(ENGINE *e);
        void ENGINE_register_all_RSA(void);
        int ENGINE_register_DSA(ENGINE *e);
        void ENGINE_unregister_DSA(ENGINE *e);
        void ENGINE_register_all_DSA(void);
        int ENGINE_register_DH(ENGINE *e);
        void ENGINE_unregister_DH(ENGINE *e);
        void ENGINE_register_all_DH(void);
        int ENGINE_register_RAND(ENGINE *e);
        void ENGINE_unregister_RAND(ENGINE *e);
        void ENGINE_register_all_RAND(void);
        int ENGINE_register_ciphers(ENGINE *e);
        void ENGINE_unregister_ciphers(ENGINE *e);
        void ENGINE_register_all_ciphers(void);
        int ENGINE_register_digests(ENGINE *e);
        void ENGINE_unregister_digests(ENGINE *e);
        void ENGINE_register_all_digests(void);
        int ENGINE_register_complete(ENGINE *e);
        int ENGINE_register_all_complete(void);

        int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
        int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
        int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
                long i, void *p, void (*f)(), int cmd_optional);
        int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
                        int cmd_optional);

        int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
        void *ENGINE_get_ex_data(const ENGINE *e, int idx);

        int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
                CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);

        ENGINE *ENGINE_new(void);
        int ENGINE_free(ENGINE *e);

        int ENGINE_set_id(ENGINE *e, const char *id);
        int ENGINE_set_name(ENGINE *e, const char *name);
        int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
        int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
        int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
        int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
        int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
        int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
        int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
        int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
        int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f);
        int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
        int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
        int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
        int ENGINE_set_flags(ENGINE *e, int flags);
        int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);

        const char *ENGINE_get_id(const ENGINE *e);
        const char *ENGINE_get_name(const ENGINE *e);
        const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
        const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
        const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
        const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
        ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
        ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
        ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
        ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
        ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
        ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
        ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
        ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
        const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
        const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
        int ENGINE_get_flags(const ENGINE *e);
        const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);

        EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
            UI_METHOD *ui_method, void *callback_data);
        EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
            UI_METHOD *ui_method, void *callback_data);

        void ENGINE_add_conf_module(void);

DESCRIPTION
       These functions create, manipulate, and use cryptographic modules in
       the form of ENGINE objects. These objects act as containers for imple-
       mentations of cryptographic algorithms, and support a reference-counted
       mechanism to allow them to be dynamically loaded in and out of the run-
       ning application.

       The cryptographic functionality that can be provided by an ENGINE
       implementation includes the following abstractions;

        RSA_METHOD - for providing alternative RSA implementations
        DSA_METHOD, DH_METHOD, RAND_METHOD - alternative DSA, DH, and RAND
        EVP_CIPHER - potentially multiple cipher algorithms (indexed by 'nid')
        EVP_DIGEST - potentially multiple hash algorithms (indexed by 'nid')
        key-loading - loading public and/or private EVP_PKEY keys

       Reference counting and handles

       Due to the modular nature of the ENGINE API, pointers to ENGINEs need
       to be treated as handles - ie. not only as pointers, but also as refer-
       ences to the underlying ENGINE object. Ie. you should obtain a new ref-
       erence when making copies of an ENGINE pointer if the copies will be
       used (and released) independantly.

       ENGINE objects have two levels of reference-counting to match the way
       in which the objects are used. At the most basic level, each ENGINE
       pointer is inherently a structural reference - you need a structural
       reference simply to refer to the pointer value at all, as this kind of
       reference is your guarantee that the structure can not be deallocated
       until you release your reference.

       However, a structural reference provides no guarantee that the ENGINE
       has been initiliased to be usable to perform any of its cryptographic
       implementations - and indeed it's quite possible that most ENGINEs will
       not initialised at all on standard setups, as ENGINEs are typically
       used to support specialised hardware. To use an ENGINE's functionality,
       you need a functional reference. This kind of reference can be consid-
       ered a specialised form of structural reference, because each func-
       tional reference implicitly contains a structural reference as well -
       however to avoid difficult-to-find programming bugs, it is recommended
       to treat the two kinds of reference independantly. If you have a func-
       tional reference to an ENGINE, you have a guarantee that the ENGINE has
       been initialised ready to perform cryptographic operations and will not
       be uninitialised or cleaned up until after you have released your ref-
       erence.

       We will discuss the two kinds of reference separately, including how to
       tell which one you are dealing with at any given point in time (after
       all they are both simply (ENGINE *) pointers, the difference is in the
       way they are used).

       Structural references

       This basic type of reference is typically used for creating new ENGINEs
       dynamically, iterating across OpenSSL's internal linked-list of loaded
       ENGINEs, reading information about an ENGINE, etc. Essentially a struc-
       tural reference is sufficient if you only need to query or manipulate
       the data of an ENGINE implementation rather than use its functionality.

       The ENGINE_new() function returns a structural reference to a new
       (empty) ENGINE object. Other than that, structural references come from
       return values to various ENGINE API functions such as; ENGINE_by_id(),
       ENGINE_get_first(), ENGINE_get_last(), ENGINE_get_next(),
       ENGINE_get_prev(). All structural references should be released by a
       corresponding to call to the ENGINE_free() function - the ENGINE object
       itself will only actually be cleaned up and deallocated when the last
       structural reference is released.

       It should also be noted that many ENGINE API function calls that accept
       a structural reference will internally obtain another reference - typi-
       cally this happens whenever the supplied ENGINE will be needed by
       OpenSSL after the function has returned. Eg. the function to add a new
       ENGINE to OpenSSL's internal list is ENGINE_add() - if this function
       returns success, then OpenSSL will have stored a new structural refer-
       ence internally so the caller is still responsible for freeing their
       own reference with ENGINE_free() when they are finished with it. In a
       similar way, some functions will automatically release the structural
       reference passed to it if part of the function's job is to do so. Eg.
       the ENGINE_get_next() and ENGINE_get_prev() functions are used for
       iterating across the internal ENGINE list - they will return a new
       structural reference to the next (or previous) ENGINE in the list or
       NULL if at the end (or beginning) of the list, but in either case the
       structural reference passed to the function is released on behalf of
       the caller.

       To clarify a particular function's handling of references, one should
       always consult that function's documentation "man" page, or failing
       that the openssl/engine.h header file includes some hints.

       Functional references

       As mentioned, functional references exist when the cryptographic func-
       tionality of an ENGINE is required to be available. A functional refer-
       ence can be obtained in one of two ways; from an existing structural
       reference to the required ENGINE, or by asking OpenSSL for the default
       operational ENGINE for a given cryptographic purpose.

       To obtain a functional reference from an existing structural reference,
       call the ENGINE_init() function. This returns zero if the ENGINE was
       not already operational and couldn't be successfully initialised (eg.
       lack of system drivers, no special hardware attached, etc), otherwise
       it will return non-zero to indicate that the ENGINE is now operational
       and will have allocated a new functional reference to the ENGINE. In
       this case, the supplied ENGINE pointer is, from the point of the view
       of the caller, both a structural reference and a functional reference -
       so if the caller intends to use it as a functional reference it should
       free the structural reference with ENGINE_free() first. If the caller
       wishes to use it only as a structural reference (eg. if the
       ENGINE_init() call was simply to test if the ENGINE seems avail-
       able/online), then it should free the functional reference; all func-
       tional references are released by the ENGINE_finish() function.

       The second way to get a functional reference is by asking OpenSSL for a
       default implementation for a given task, eg. by
       ENGINE_get_default_RSA(), ENGINE_get_default_cipher_engine(), etc.
       These are discussed in the next section, though they are not usually
       required by application programmers as they are used automatically when
       creating and using the relevant algorithm-specific types in OpenSSL,
       such as RSA, DSA, EVP_CIPHER_CTX, etc.

       Default implementations

       For each supported abstraction, the ENGINE code maintains an internal
       table of state to control which implementations are available for a
       given abstraction and which should be used by default. These implemen-
       tations are registered in the tables separated-out by an 'nid' index,
       because abstractions like EVP_CIPHER and EVP_DIGEST support many dis-
       tinct algorithms and modes - ENGINEs will support different numbers and
       combinations of these. In the case of other abstractions like RSA, DSA,
       etc, there is only one "algorithm" so all implementations implicitly
       register using the same 'nid' index. ENGINEs can be registered into
       these tables to make themselves available for use automatically by the
       various abstractions, eg. RSA. For illustrative purposes, we continue
       with the RSA example, though all comments apply similarly to the other
       abstractions (they each get their own table and linkage to the corre-
       sponding section of openssl code).

       When a new RSA key is being created, ie. in RSA_new_method(), a
       "get_default" call will be made to the ENGINE subsystem to process the
       RSA state table and return a functional reference to an initialised
       ENGINE whose RSA_METHOD should be used. If no ENGINE should (or can) be
       used, it will return NULL and the RSA key will operate with a NULL
       ENGINE handle by using the conventional RSA implementation in OpenSSL
       (and will from then on behave the way it used to before the ENGINE API
       existed - for details see RSA_new_method(3)).

       Each state table has a flag to note whether it has processed this
       "get_default" query since the table was last modified, because to
       process this question it must iterate across all the registered ENGINEs
       in the table trying to initialise each of them in turn, in case one of
       them is operational. If it returns a functional reference to an ENGINE,
       it will also cache another reference to speed up processing future
       queries (without needing to iterate across the table). Likewise, it
       will cache a NULL response if no ENGINE was available so that future
       queries won't repeat the same iteration unless the state table changes.
       This behaviour can also be changed; if the ENGINE_TABLE_FLAG_NOINIT
       flag is set (using ENGINE_set_table_flags()), no attempted initialisa-
       tions will take place, instead the only way for the state table to
       return a non-NULL ENGINE to the "get_default" query will be if one is
       expressly set in the table. Eg.  ENGINE_set_default_RSA() does the same
       job as ENGINE_register_RSA() except that it also sets the state table's
       cached response for the "get_default" query.

       In the case of abstractions like EVP_CIPHER, where implementations are
       indexed by 'nid', these flags and cached-responses are distinct for
       each 'nid' value.

       It is worth illustrating the difference between "registration" of
       ENGINEs into these per-algorithm state tables and using the alternative
       "set_default" functions. The latter handles both "registration" and
       also setting the cached "default" ENGINE in each relevant state table -
       so registered ENGINEs will only have a chance to be initialised for use
       as a default if a default ENGINE wasn't already set for the same state
       table.  Eg. if ENGINE X supports cipher nids {A,B} and RSA, ENGINE Y
       supports ciphers {A} and DSA, and the following code is executed;

        ENGINE_register_complete(X);
        ENGINE_set_default(Y, ENGINE_METHOD_ALL);
        e1 = ENGINE_get_default_RSA();
        e2 = ENGINE_get_cipher_engine(A);
        e3 = ENGINE_get_cipher_engine(B);
        e4 = ENGINE_get_default_DSA();
        e5 = ENGINE_get_cipher_engine(C);

       The results would be as follows;

        assert(e1 == X);
        assert(e2 == Y);
        assert(e3 == X);
        assert(e4 == Y);
        assert(e5 == NULL);

       Application requirements

       This section will explain the basic things an application programmer
       should support to make the most useful elements of the ENGINE function-
       ality available to the user. The first thing to consider is whether the
       programmer wishes to make alternative ENGINE modules available to the
       application and user. OpenSSL maintains an internal linked list of
       "visible" ENGINEs from which it has to operate - at start-up, this list
       is empty and in fact if an application does not call any ENGINE API
       calls and it uses static linking against openssl, then the resulting
       application binary will not contain any alternative ENGINE code at all.
       So the first consideration is whether any/all available ENGINE imple-
       mentations should be made visible to OpenSSL - this is controlled by
       calling the various "load" functions, eg.

        /* Make the "dynamic" ENGINE available */
        void ENGINE_load_dynamic(void);
        /* Make the CryptoSwift hardware acceleration support available */
        void ENGINE_load_cswift(void);
        /* Make support for nCipher's "CHIL" hardware available */
        void ENGINE_load_chil(void);
        ...
        /* Make ALL ENGINE implementations bundled with OpenSSL available */
        void ENGINE_load_builtin_engines(void);

       Having called any of these functions, ENGINE objects would have been
       dynamically allocated and populated with these implementations and
       linked into OpenSSL's internal linked list. At this point it is impor-
       tant to mention an important API function;

        void ENGINE_cleanup(void);

       If no ENGINE API functions are called at all in an application, then
       there are no inherent memory leaks to worry about from the ENGINE func-
       tionality, however if any ENGINEs are "load"ed, even if they are never
       registered or used, it is necessary to use the ENGINE_cleanup() func-
       tion to correspondingly cleanup before program exit, if the caller
       wishes to avoid memory leaks. This mechanism uses an internal callback
       registration table so that any ENGINE API functionality that knows it
       requires cleanup can register its cleanup details to be called during
       ENGINE_cleanup(). This approach allows ENGINE_cleanup() to clean up
       after any ENGINE functionality at all that your program uses, yet
       doesn't automatically create linker dependencies to all possible ENGINE
       functionality - only the cleanup callbacks required by the functional-
       ity you do use will be required by the linker.

       The fact that ENGINEs are made visible to OpenSSL (and thus are linked
       into the program and loaded into memory at run-time) does not mean they
       are "registered" or called into use by OpenSSL automatically - that be-
       haviour is something for the application to have control over. Some
       applications will want to allow the user to specify exactly which
       ENGINE they want used if any is to be used at all. Others may prefer to
       load all support and have OpenSSL automatically use at run-time any
       ENGINE that is able to successfully initialise - ie. to assume that
       this corresponds to acceleration hardware attached to the machine or
       some such thing. There are probably numerous other ways in which appli-
       cations may prefer to handle things, so we will simply illustrate the
       consequences as they apply to a couple of simple cases and leave devel-
       opers to consider these and the source code to openssl's builtin utili-
       ties as guides.

       Using a specific ENGINE implementation

       Here we'll assume an application has been configured by its user or
       admin to want to use the "ACME" ENGINE if it is available in the ver-
       sion of OpenSSL the application was compiled with. If it is available,
       it should be used by default for all RSA, DSA, and symmetric cipher
       operation, otherwise OpenSSL should use its builtin software as per
       usual. The following code illustrates how to approach this;

        ENGINE *e;
        const char *engine_id = "ACME";
        ENGINE_load_builtin_engines();
        e = ENGINE_by_id(engine_id);
        if(!e)
            /* the engine isn't available */
            return;
        if(!ENGINE_init(e)) {
            /* the engine couldn't initialise, release 'e' */
            ENGINE_free(e);
            return;
        }
        if(!ENGINE_set_default_RSA(e))
            /* This should only happen when 'e' can't initialise, but the previous
             * statement suggests it did. */
            abort();
        ENGINE_set_default_DSA(e);
        ENGINE_set_default_ciphers(e);
        /* Release the functional reference from ENGINE_init() */
        ENGINE_finish(e);
        /* Release the structural reference from ENGINE_by_id() */
        ENGINE_free(e);

       Automatically using builtin ENGINE implementations

       Here we'll assume we want to load and register all ENGINE implementa-
       tions bundled with OpenSSL, such that for any cryptographic algorithm
       required by OpenSSL - if there is an ENGINE that implements it and can
       be initialise, it should be used. The following code illustrates how
       this can work;

        /* Load all bundled ENGINEs into memory and make them visible */
        ENGINE_load_builtin_engines();
        /* Register all of them for every algorithm they collectively implement */
        ENGINE_register_all_complete();

       That's all that's required. Eg. the next time OpenSSL tries to set up
       an RSA key, any bundled ENGINEs that implement RSA_METHOD will be
       passed to ENGINE_init() and if any of those succeed, that ENGINE will
       be set as the default for use with RSA from then on.

       Advanced configuration support

       There is a mechanism supported by the ENGINE framework that allows each
       ENGINE implementation to define an arbitrary set of configuration "com-
       mands" and expose them to OpenSSL and any applications based on
       OpenSSL. This mechanism is entirely based on the use of name-value
       pairs and and assumes ASCII input (no unicode or UTF for now!), so it
       is ideal if applications want to provide a transparent way for users to
       provide arbitrary configuration "directives" directly to such ENGINEs.
       It is also possible for the application to dynamically interrogate the
       loaded ENGINE implementations for the names, descriptions, and input
       flags of their available "control commands", providing a more flexible
       configuration scheme. However, if the user is expected to know which
       ENGINE device he/she is using (in the case of specialised hardware,
       this goes without saying) then applications may not need to concern
       themselves with discovering the supported control commands and simply
       prefer to allow settings to passed into ENGINEs exactly as they are
       provided by the user.

       Before illustrating how control commands work, it is worth mentioning
       what they are typically used for. Broadly speaking there are two uses
       for control commands; the first is to provide the necessary details to
       the implementation (which may know nothing at all specific to the host
       system) so that it can be initialised for use. This could include the
       path to any driver or config files it needs to load, required network
       addresses, smart-card identifiers, passwords to initialise password-
       protected devices, logging information, etc etc. This class of commands
       typically needs to be passed to an ENGINE before attempting to ini-
       tialise it, ie. before calling ENGINE_init(). The other class of com-
       mands consist of settings or operations that tweak certain behaviour or
       cause certain operations to take place, and these commands may work
       either before or after ENGINE_init(), or in same cases both. ENGINE
       implementations should provide indications of this in the descriptions
       attached to builtin control commands and/or in external product docu-
       mentation.

       Issuing control commands to an ENGINE

       Let's illustrate by example; a function for which the caller supplies
       the name of the ENGINE it wishes to use, a table of string-pairs for
       use before initialisation, and another table for use after initialisa-
       tion. Note that the string-pairs used for control commands consist of a
       command "name" followed by the command "parameter" - the parameter
       could be NULL in some cases but the name can not. This function should
       initialise the ENGINE (issuing the "pre" commands beforehand and the
       "post" commands afterwards) and set it as the default for everything
       except RAND and then return a boolean success or failure.

        int generic_load_engine_fn(const char *engine_id,
                                   const char **pre_cmds, int pre_num,
                                   const char **post_cmds, int post_num)
        {
            ENGINE *e = ENGINE_by_id(engine_id);
            if(!e) return 0;
            while(pre_num--) {
                if(!ENGINE_ctrl_cmd_string(e, pre_cmds[0], pre_cmds[1], 0)) {
                    fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id,
                        pre_cmds[0], pre_cmds[1] ? pre_cmds[1] : "(NULL)");
                    ENGINE_free(e);
                    return 0;
                }
                pre_cmds += 2;
            }
            if(!ENGINE_init(e)) {
                fprintf(stderr, "Failed initialisation\n");
                ENGINE_free(e);
                return 0;
            }
            /* ENGINE_init() returned a functional reference, so free the structural
             * reference from ENGINE_by_id(). */
            ENGINE_free(e);
            while(post_num--) {
                if(!ENGINE_ctrl_cmd_string(e, post_cmds[0], post_cmds[1], 0)) {
                    fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id,
                        post_cmds[0], post_cmds[1] ? post_cmds[1] : "(NULL)");
                    ENGINE_finish(e);
                    return 0;
                }
                post_cmds += 2;
            }
            ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND);
            /* Success */
            return 1;
        }

       Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can
       relax the semantics of the function - if set non-zero it will only
       return failure if the ENGINE supported the given command name but
       failed while executing it, if the ENGINE doesn't support the command
       name it will simply return success without doing anything. In this case
       we assume the user is only supplying commands specific to the given
       ENGINE so we set this to FALSE.

       Discovering supported control commands

       It is possible to discover at run-time the names, numerical-ids,
       descriptions and input parameters of the control commands supported
       from a structural reference to any ENGINE. It is first important to
       note that some control commands are defined by OpenSSL itself and it
       will intercept and handle these control commands on behalf of the
       ENGINE, ie. the ENGINE's ctrl() handler is not used for the control
       command. openssl/engine.h defines a symbol, ENGINE_CMD_BASE, that all
       control commands implemented by ENGINEs from. Any command value lower
       than this symbol is considered a "generic" command is handled directly
       by the OpenSSL core routines.

       It is using these "core" control commands that one can discover the the
       control commands implemented by a given ENGINE, specifically the com-
       mands;

        #define ENGINE_HAS_CTRL_FUNCTION               10
        #define ENGINE_CTRL_GET_FIRST_CMD_TYPE         11
        #define ENGINE_CTRL_GET_NEXT_CMD_TYPE          12
        #define ENGINE_CTRL_GET_CMD_FROM_NAME          13
        #define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD      14
        #define ENGINE_CTRL_GET_NAME_FROM_CMD          15
        #define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD      16
        #define ENGINE_CTRL_GET_DESC_FROM_CMD          17
        #define ENGINE_CTRL_GET_CMD_FLAGS              18

       Whilst these commands are automatically processed by the OpenSSL frame-
       work code, they use various properties exposed by each ENGINE by which
       to process these queries. An ENGINE has 3 properties it exposes that
       can affect this behaviour; it can supply a ctrl() handler, it can spec-
       ify ENGINE_FLAGS_MANUAL_CMD_CTRL in the ENGINE's flags, and it can
       expose an array of control command descriptions.  If an ENGINE speci-
       fies the ENGINE_FLAGS_MANUAL_CMD_CTRL flag, then it will simply pass
       all these "core" control commands directly to the ENGINE's ctrl() han-
       dler (and thus, it must have supplied one), so it is up to the ENGINE
       to reply to these "discovery" commands itself. If that flag is not set,
       then the OpenSSL framework code will work with the following rules;

        if no ctrl() handler supplied;
            ENGINE_HAS_CTRL_FUNCTION returns FALSE (zero),
            all other commands fail.
        if a ctrl() handler was supplied but no array of control commands;
            ENGINE_HAS_CTRL_FUNCTION returns TRUE,
            all other commands fail.
        if a ctrl() handler and array of control commands was supplied;
            ENGINE_HAS_CTRL_FUNCTION returns TRUE,
            all other commands proceed processing ...

       If the ENGINE's array of control commands is empty then all other com-
       mands will fail, otherwise; ENGINE_CTRL_GET_FIRST_CMD_TYPE returns the
       identifier of the first command supported by the ENGINE,
       ENGINE_GET_NEXT_CMD_TYPE takes the identifier of a command supported by
       the ENGINE and returns the next command identifier or fails if there
       are no more, ENGINE_CMD_FROM_NAME takes a string name for a command and
       returns the corresponding identifier or fails if no such command name
       exists, and the remaining commands take a command identifier and return
       properties of the corresponding commands. All except
       ENGINE_CTRL_GET_FLAGS return the string length of a command name or
       description, or populate a supplied character buffer with a copy of the
       command name or description. ENGINE_CTRL_GET_FLAGS returns a bit-
       wise-OR'd mask of the following possible values;

        #define ENGINE_CMD_FLAG_NUMERIC                (unsigned int)0x0001
        #define ENGINE_CMD_FLAG_STRING                 (unsigned int)0x0002
        #define ENGINE_CMD_FLAG_NO_INPUT               (unsigned int)0x0004
        #define ENGINE_CMD_FLAG_INTERNAL               (unsigned int)0x0008

       If the ENGINE_CMD_FLAG_INTERNAL flag is set, then any other flags are
       purely informational to the caller - this flag will prevent the command
       being usable for any higher-level ENGINE functions such as
       ENGINE_ctrl_cmd_string().  "INTERNAL" commands are not intended to be
       exposed to text-based configuration by applications, administrations,
       users, etc. These can support arbitrary operations via ENGINE_ctrl(),
       including passing to and/or from the control commands data of any arbi-
       trary type. These commands are supported in the discovery mechanisms
       simply to allow applications determinie if an ENGINE supports certain
       specific commands it might want to use (eg. application "foo" might
       query various ENGINEs to see if they implement "FOO_GET_VEN-
       DOR_LOGO_GIF" - and ENGINE could therefore decide whether or not to
       support this "foo"-specific extension).

       Future developments

       The ENGINE API and internal architecture is currently being reviewed.
       Slated for possible release in 0.9.8 is support for transparent loading
       of "dynamic" ENGINEs (built as self-contained shared-libraries). This
       would allow ENGINE implementations to be provided independantly of
       OpenSSL libraries and/or OpenSSL-based applications, and would also
       remove any requirement for applications to explicitly use the "dynamic"
       ENGINE to bind to shared-library implementations.

SEE ALSO
       rsa(3), dsa(3), dh(3), rand(3), RSA_new_method(3)



0.9.7d                            2005-02-24                         engine(3)
=2949
+1122
(477)