Segmentation fault in crypto:dh_generate_key R13B4

Paul Guyot pguyot@REDACTED
Tue Jul 6 10:12:36 CEST 2010


Le 6 juil. 2010 à 09:50, erlang-questions-digest-help@REDACTED a écrit :

> De : Max Lapshin <max.lapshin@REDACTED>
> Date : 5 juillet 2010 22:36:11 HAEC
> À : Erlang-Questions Questions <erlang-questions@REDACTED>
> Objet : Segmentation fault in crypto:dh_generate_key R13B4
> 
> 
> Erlang R13B4, OS X 10.6, erlang build from homebrew
> 
> 
> otool -L /usr/local/lib/erlang/lib/crypto-1.6.4/priv/lib/crypto_drv.so
> /usr/local/lib/erlang/lib/crypto-1.6.4/priv/lib/crypto_drv.so:
> 	/usr/lib/libcrypto.0.9.8.dylib (compatibility version 0.9.8, current
> version 0.9.8)
> 	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
> version 125.0.0)
> 
> 
> Starting attached file leads to Segmentation Fault:
> 
> 
> maxbp:erlyvideo max$ ./dh_check.erl
> Segmentation fault
> 
> What should I do more to fix this problem?
> <dh_check.erl>

As of R14A, crypto has been rewritten and is now based on NIF instead of relying on a linked-in driver. While this doesn't excuse the seg fault, I believe there is a bug in your code:

  DH_P = <<16#ff, 16#ff, 16#ff, 16#ff, 16#ff,
            		16#ff, 16#ff, 16#ff, 16#c9, 16#0f, 16#da, 16#a2, 16#21,
            		16#68, 16#c2, 16#34, 16#c4, 16#c6, 16#62, 16#8b, 16#80,
            		16#dc, 16#1c, 16#d1, 16#29, 16#02, 16#4e, 16#08, 16#8a,
            		16#67, 16#cc, 16#74, 16#02, 16#0b, 16#be, 16#a6, 16#3b,
            		16#13, 16#9b, 16#22, 16#51, 16#4a, 16#08, 16#79, 16#8e,
            		16#34, 16#04, 16#dd, 16#ef, 16#95, 16#19, 16#b3, 16#cd,
            		16#3a, 16#43, 16#1b, 16#30, 16#2b, 16#0a, 16#6d, 16#f2,
            		16#5f, 16#14, 16#37, 16#4f, 16#e1, 16#35, 16#6d, 16#6d,
            		16#51, 16#c2, 16#45, 16#e4, 16#85, 16#b5, 16#76, 16#62,
            		16#5e, 16#7e, 16#c6, 16#f4, 16#4c, 16#42, 16#e9, 16#a6,
            		16#37, 16#ed, 16#6b, 16#0b, 16#ff, 16#5c, 16#b6, 16#f4,
            		16#06, 16#b7, 16#ed, 16#ee, 16#38, 16#6b, 16#fb, 16#5a,
            		16#89, 16#9f, 16#a5, 16#ae, 16#9f, 16#24, 16#11, 16#7c,
            		16#4b, 16#1f, 16#e6, 16#49, 16#28, 16#66, 16#51, 16#ec,
            		16#e6, 16#53, 16#81, 16#ff, 16#ff, 16#ff, 16#ff, 16#ff,
            		16#ff, 16#ff, 16#ff>>,
  DH_G = 2,
  crypto:dh_generate_key([DH_P, DH_G]).

You pass a binary which is not a mpint() and an integer to crypto:dh_generate_key/1.
You should call crypto:mpint/1 instead, e.g.:

  DH_P = crypto:mpint(16#ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff),
  DH_G = crypto:mpint(2),
  crypto:dh_generate_key([DH_P, DH_G]).
  
Paul
-- 
Semiocast                    http://semiocast.com/
+33.175000290 - 62 bis rue Gay-Lussac, 75005 Paris



More information about the erlang-questions mailing list