segfault calling gcry_mpi_powm

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


Hi,

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

gcry_mpi_scan

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 ws-001.bononline.nl kernel: traps: sonssc[6198]
general protection fault ip:7fa60c1e4359 sp:7fa60afbaa10 error:0 in
libc-2.32.so[7fa60c183000+148000]
Jan 05 05:30:36 ws-001.bononline.nl systemd[1]: Created slice
system-systemd\x2dcoredump.slice.
Jan 05 05:30:36 ws-001.bononline.nl systemd[1]: Started Process Core
Dump (PID 6212/UID 0).
Jan 05 05:30:36 ws-001.bononline.nl systemd-coredump[6213]: []
Process 6196 (sonssc) of user 0 dumped core.

                                                           Stack trace
of thread 6198:
                                                           #0
0x00007fa60c1e4359 n/a (libc.so.6 + 0x83359)
                                                           #1
0x00007fa60c6a7395 n/a (libgcrypt.so.20 + 0x10395)
                                                           #2
0x00007fa60c76910b n/a (libgcrypt.so.20 + 0xd210b)
                                                           #3
0x00005587f4b22ad4 n/a
(/home/sbon/Projects/fuse/fs-workspace/src/sonssc + 0x42ad4)
                                                           #4
0x87fc013cf9521000 n/a (n/a + 0x0)

and gdb backtrace looks like:

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f20b7e5f359 in ?? () from /lib64/libc.so.6
[Current thread is 1 (Thread 0x7f20b6c37640 (LWP 15027))]
(gdb) bt
#0  0x00007f20b7e5f359 in  () at /lib64/libc.so.6
#1  0x00007f20b8322395 in  () at /usr/lib64/libgcrypt.so.20
#2  0x00007f20b83e410b in  () at /usr/lib64/libgcrypt.so.20
#3  0x000055e95c8bbad4 in dh_create_local_key (k=0x7f20b6c36730) at
ssh/keyexchange/dh.c:350
#4  0x000055e95c8bc939 in start_diffiehellman_client
(connection=0x7f20a40021c0, k=0x7f20b6c36730, H=0x7f20b6c36100) at
ssh/keyexchange/key-exchange.c:389

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

Thanks in advance,

Stfe Bon
the Netherlands



More information about the Gcrypt-devel mailing list