Slide 29
Slide 29 text
OpenSSL RSA RSA_public_encrypt
in C
int RSA_public_encrypt(int flen, unsigned char *from,
unsigned char *to, RSA *rsa, int padding);
in GO
func (m *M) RSA_public_encrypt(plain []byte) []byte {
cipher := (unsafe.Pointer)(C.malloc(C.size_t(C.RSA_size(m.ctx))))
defer C.free(unsafe.Pointer(cipher))
ret := C.RSA_public_encrypt(
C
C.
.i
in
nt
t(
(l
le
en
n(
(p
pl
la
ai
in
n)
))
),
, /
//
/ f
fl
le
en
n
(
(*
*C
C.
.u
uc
ch
ha
ar
r)
)(
(&
&p
pl
la
ai
in
n[
[0
0]
])
),
, /
//
/ f
fr
ro
om
m
(
(*
*C
C.
.u
uc
ch
ha
ar
r)
)(
(c
ci
ip
ph
he
er
r)
),
, /
//
/ t
to
o
m
m.
.c
ct
tx
x,
, /
//
/ R
RS
SA
A *
*r
rs
sa
a
C
C.
.R
RS
SA
A_
_P
PK
KC
CS
S1
1_
_P
PA
AD
DD
DI
IN
NG
G)
) /
//
/ p
pa
ad
dd
di
in
ng
g
return C.GoBytes(cipher, ret)
}
Interfacing C libraries with GO