segfault calling gcry_mpi_powm

Stef Bon stefbon at
Tue Jan 5 06:55:12 CET 2021


I'm dealing with a serious problem. My program is running into a
segfault, and I cannot solve that. I've been looking at it for more
than a week, and do not know why it segfaults.

I'm using gcry_mpi_powm to calculate the "e", "f" and shared key in
Diffie-Hellman key exchange.

a. the values p, g, x, e and f (all type gcry_mpi_t) are initialized
with gcry_mpi_new(0).

b. p and g are set to fixed values, read from hardcoded values using


with format GCRYMPI_FMT_USG.

c. x is set using gcry_mpi_randomize.

d. e is calculated like : gcry_mpi_powm(e, g, x, p)

now the journal entries look like:

Jan 05 05:30:36 kernel: traps: sonssc[6198]
general protection fault ip:7fa60c1e4359 sp:7fa60afbaa10 error:0 in[7fa60c183000+148000]
Jan 05 05:30:36 systemd[1]: Created slice
Jan 05 05:30:36 systemd[1]: Started Process Core
Dump (PID 6212/UID 0).
Jan 05 05:30:36 systemd-coredump[6213]: []
Process 6196 (sonssc) of user 0 dumped core.

                                                           Stack trace
of thread 6198:
0x00007fa60c1e4359 n/a ( + 0x83359)
0x00007fa60c6a7395 n/a ( + 0x10395)
0x00007fa60c76910b n/a ( + 0xd210b)
0x00005587f4b22ad4 n/a
(/home/sbon/Projects/fuse/fs-workspace/src/sonssc + 0x42ad4)
0x87fc013cf9521000 n/a (n/a + 0x0)

and gdb backtrace looks like:

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f20b7e5f359 in ?? () from /lib64/
[Current thread is 1 (Thread 0x7f20b6c37640 (LWP 15027))]
(gdb) bt
#0  0x00007f20b7e5f359 in  () at /lib64/
#1  0x00007f20b8322395 in  () at /usr/lib64/
#2  0x00007f20b83e410b in  () at /usr/lib64/
#3  0x000055e95c8bbad4 in dh_create_local_key (k=0x7f20b6c36730) at
#4  0x000055e95c8bc939 in start_diffiehellman_client
(connection=0x7f20a40021c0, k=0x7f20b6c36730, H=0x7f20b6c36100) at

I'm stuck here. Can somebody help me here?

Thanks in advance,

Stfe Bon
the Netherlands

More information about the Gcrypt-devel mailing list