# openssl ## generate key ./openssl genrsa -out key128.pem 128 ## extract public key from private key ./openssl rsa -in key128.pem -pubout -out pub128.pem ## convert to pem `ssh-keygen -f ~/.ssh/id_rsa.pub -e -m PKCS8 > ~/.ssh/id_rsa.pub.pem` ## encrypt `echo "hello gowtham" | openssl rsautl -encrypt -pubin -inkey ~/.ssh/id_rsa.pub.pem -raw> hello.crypt` - when -raw input text should be same length-1 as key ## decrypt `openssl rsautl -decrypt -inkey ~/.ssh/id_rsa -in hello.crypt -raw` ## print the private key contents `openssl rsa -in ~/.ssh/id_rsa -noout -text` prime1: p prime2: q modulus: N = p * q publicExponent: e privateExponent: d exponent1 = dp exponent2 = dq coefficient = qInv ## build ``` cd openssl export CC=clang mkdir install/aarch64 make clean ./config --prefix=$(pwd)/install/aarch64 --openssldir=`pwd`/install/aarch64 make -j`nproc` make install_sw ``` ## id_rsa - base64 encoded - the binary format is ASN.1 - contains: ``` (gdb) p *rsa $62 = {dummy_zero = 0, libctx = 0x7ffff7ed8a20 , version = 0, meth = 0x7ffff7ed62e8 , engine = 0x0, n = 0x555555690c60, e = 0x5555556912e0, d = 0x555555690c40, p = 0x555555691320, q = 0x555555691300, dmp1 = 0x555555691490, dmq1 = 0x5555556914b0, iqmp = 0x555555691560, pss_params = {hash_algorithm_nid = 0, mask_gen = {algorithm_nid = 0, hash_algorithm_nid = 0}, salt_len = 0, trailer_field = 0}, pss = 0x0, prime_infos = 0x0, ex_data = {ctx = 0x0, sk = 0x0}, references = 2, flags = 6, _method_mod_n = 0x5555556b83d0, _method_mod_p = 0x5555556829e0, _method_mod_q = 0x55555568b080, blinding = 0x5555556890b0, mt_blinding = 0x0, lock = 0x555555690940, dirty_cnt = 0} ``` # RSA p,q - 2 prime numbers n=p*q ϕ=(p-1)*(q-1) e=>e<ϕ and gcd(e,ϕ)=1 i.e e and ϕ are coprimes, a prime would be easy d=>(d*e)%ϕ=1 => d≡e^(-1)modϕ c=(m^e)%n (modular exponentiation; often done using squareNmultiply) c - cipher m=(c^d)%n m - message e=65537 often because of low hamming weight(number of bits having 1) - d is as large as the key hence we convert it into Bignumber(a multiprecision system) with base 64. for 1024 bit key, max(d)=(2^1024)-1. ## GPU ### Lucas Gillsjo, Linkopings university - reduce the size of d and n from k bits to k/2 bits using Chinese Remainder Theorem(CRT) with Fermat's little theorem. this splits modular exponentiation into two modular exponentiations giving more llism. mp=(c^d)%p mq=(c^d)%q dP=d%(p-1) dQ=d%(q-1) qInv=(q^-1)%p Applying **Fermat's little** theorem a^p≡a (mod p) => (a^p)%p=a%p mp≡(c^dP)%p mq≡(c^dQ)%q As per Extended Euclidean algorithm x=(a1n2((n2%n1)^-1))+(a2n1(n1%n2)^-1) m=((c^dP)q((q%p)^-1))+((c^dQ)p((p%q)^-1)) m=mq+q.((mp-mq).qInv%p) - with squareNmultiply we can reduce 2^k-1 modular multiplications to k;k=bits in a integer. 1. x^m=x.(x^2)^((m-1)/2), if m is odd =(x^2)^(m/2), if m is even 2. (a.b)%c=((a%c).(b%c))%c Thus to calculate (g^e)%m j=>e=(e_j,e_j-1,e_j-2,...,e_1,e_0)_2 let A=1 for i=j down to 0 do A=(A^2)%m if e_i==1 then A=(A.g)%m return A - Montgomery reduction removes the need of doing a trial division when doing the modulo operation by converting the integers to montgomerized form where we can choose which modulus we want to use. We choose a modulus which is a power of 2 which means that all modulo and division operations will be just bitmasking and bitshifting. øverline{a} = a · R mod m where gcd(R,m) = 1,m < R extended euclidean algorithm: ## debug ```bash cp ../RSA-OpenCL/bn_cl.cpp crypto/bn/ ./Configure --prefix=$(pwd)/install --openssldir=$(pwd)/install '-ggdb -O0 -Wl,-rpath,$(LIBRPATH) -I/opt/rocm/opencl/include -L/opt/rocm/opencl/lib -lOpenCL -lgmp -lm -lstdc++ ./config -DOPENSSL_USE_GMP -lgmp # for now the modular exponentiation is the only op performed with GMP bear --append -- make -j6 make install_sw gdb -i=mi --args /home/gowtham/openssl/install/bin/openssl pkeyutl -decrypt -inkey /home/gowtham/.ssh/id_rsa -in /home/gowtham/openssl/install/bin/hello.crypt -dontblind gdb -i=mi --args /Users/Gowtham/workspace/openssl/install/bin/openssl pkeyutl -decrypt -inkey /Users/Gowtham/.ssh/id_rsa -in /Users/Gowtham/workspace/openssl/install/bin/balance.crypt -dontblind 0x555555554000 0x555555590000 0x3c000 0x0 r--p /mnt/ssd2/openssl/install/bin/openssl 0x555555662000 0x5555556a5999 0x44000 0x0 rw-p [heap] 0x7ffff76c8000 0x7ffff76cb000 0x3000 0x0 rw-p 0x7ffff78e6000 0x7ffff78f2999 0xd000 0x0 rw-p 0x7ffff7906000 0x7ffff79bc000 0xb6000 0x0 r--p /mnt/ssd2/openssl/install/lib64/libcrypto.so.3 0x7ffff7ed9000 0x7ffff7edb999 0x3000 0x0 rw-p 0x7ffff7edc000 0x7ffff7efc000 0x20000 0x0 r--p /mnt/ssd2/openssl/install/lib64/libssl.so.3 0x7ffff7fbb000 0x7ffff7fbc999 0x2000 0x0 rw-p 0x7ffff7fbd000 0x7ffff7fc1000 0x4000 0x0 r--p [vvar] 0x7ffff7ffd000 0x7ffff7ffe999 0x2000 0x39000 rw-p /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 0x7ffffffde000 0x7fffffffe999 0x21000 0x0 rw-p [stack] 0xffffffffff600000 0xffffffffff601000 0x1000 0x0 --xp [vsyscall] *rsa->n->d=15172223546846644367 rsa->n->d=(unsigned long *)0x555555679b70 // opening id_rsa and loading p *(FILE*)ret->ptr $47 = {_flags = -72539000, _IO_read_ptr = 0x0, _IO_read_end = 0x0, _IO_read_base = 0x0, _IO_write_base = 0x0, _IO_write_ptr = 0x0, _IO_write_end = 0x0, _IO_buf_base = 0x0, _IO_buf_end = 0x0, _IO_save_base = 0x0, _IO_backup_base = 0x0, _IO_save_end = 0x0, _markers = 0x0, _chain = 0x7ffff78e56a0 <_IO_2_1_stderr_>, _fileno = 3, _flags2 = 0, _old_offset = 0, _cur_column = 0, _vtable_offset = 0 '\000', _shortbuf = "", _lock = 0x555555677b40, _offset = -1, _codecvt = 0x0, _wide_data = 0x555555677b50, _freeres_list = 0x0, _freeres_buf = 0x0, __pad5 = 0, _mode = 0, _unused2 = '\000' } p *(BIO*)ret $45 = 0x555555682910 {libctx = 0x0, method = 0x7ffff7e7e3a0 , callback = 0x0, callback_ex = 0x0, cb_arg = 0x0, init = 1, shutdown = 1, flags = 0, retry_reason = 0, num = 0, (FILE*)ptr = 0x555555677a60, next_bio = 0x0, prev_bio = 0x0, references = 1, num_read = 0, num_write = 0, ex_data = {ctx = 0x0, sk = 0x0}, lock = 0x5555556829a0} file_open_stream (source=0x555555682910, uri=0x7fffffffeaec "/home/gowtham/.ssh/id_rsa", provctx=0x5555556824a0) at providers/implementations/storemgmt/file_store.c:157 162 ((file_ctx_st*)ctx)->_.file.file = (BIO*)source; p ((file_ctx_st*)ctx)->provctx $57 = (PROV_CTX*) 0x5555556824a0 {handle = 0x555555682360, libctx = 0x7ffff7ed8a20 , corebiometh = 0x55555567dca0} p *(((file_ctx_st:OSSL_STORE_LOADER_CTX)*)ctx) $53 = {provctx = 0x5555556824a0, uri = 0x555555682540 "/home/gowtham/.ssh/id_rsa", type = IS_FILE, _ = {file = {file = 0x555555682910, decoderctx = 0x0, input_type = 0x0, propq = 0x0}, dir = {ctx = 0x555555682910, end_reached = 0, search_name = "\000\000\000\000\000\000\000\000", last_entry = 0x0, last_errno = 0}}, expected_type = 0} // OSSL_STORE_open_ex at crypto/store/store_lib.c:138 p *(OSSL_STORE_LOADER_CTX*)loader_ctx $33 = {e = 0x5555556824a0, keyid = 0x555555682540 "/home/gowtham/.ssh/id_rsa", expected = 0, loaded = 0} p *(OSSL_STORE_CTX *)ctx $64 = 0x55555567bae0 {loader = 0x55555567ba00, fetched_loader = 0x55555567ba00, loader_ctx = 0x55555567b930, post_process = 0x0, post_process_data = 0x0, expected_type = 0, properties = 0x0, loading = 0, error_flag = 0, cached_info = 0x0, pwdata = {type = is_ui_method, _ = {expl_passphrase = {passphrase_copy = 0x55555567ca20 "\240\351gUUU", passphrase_len = 140737488343312}, pem_password = {password_cb = 0x55555567ca20, password_cbarg = 0x7fffffffd110}, ossl_passphrase = {passphrase_cb = 0x55555567ca20, passphrase_cbarg = 0x7fffffffd110}, ui_method = {ui_method = 0x55555567ca20, ui_method_data = 0x7fffffffd110}}, flag_cache_passphrase = 1, cached_passphrase = 0x0, cached_passphrase_len = 0}} // this is where id_rsa is being read #3 0x00007ffff7c59e31 in get_header_and_data (bp=0x55555568a560, header=0x7fffffffc868, data=0x7fffffffc860, name=0x55555568a860 "RSA PRIVATE KEY", flags=2) at crypto/pem/pem_lib.c:898 #4 0x00007ffff7c59647 in PEM_read_bio_ex (bp=0x55555568a560, name_out=0x7fffffffcb88, header=0x7fffffffcb80, data=0x7fffffffcb70, len_out=0x7fffffffcb68, flags=2) at crypto/pem/pem_lib.c:953 #5 0x00007ffff7c5949b in PEM_read_bio (bp=0x55555568a560, name=0x7fffffffcb88, header=0x7fffffffcb80, data=0x7fffffffcb70, len=0x7fffffffcb68) at crypto/pem/pem_lib.c:1010 #6 0x00007ffff7d53471 in read_pem (provctx=0x5555556824a0, cin=0x5555556894f0, pem_name=0x7fffffffcb88, pem_header=0x7fffffffcb80, data=0x7fffffffcb70, len=0x7fffffffcb68) at providers/implementations/encode_decode/decode_pem2der.c:40 #7 0x00007ffff7d530bc in pem2der_decode (vctx=0x5555556890f0, cin=0x5555556894f0, selection=0, data_cb=0x7ffff7b03c40 , data_cbarg=0x7fffffffcca0, pw_cb=0x7ffff7b8b2f0 , pw_cbarg=0x555555682a18) at providers/implementations/encode_decode/decode_pem2der.c:144 #8 0x00007ffff7b042f2 in decoder_process (params=0x0, arg=0x7fffffffcdb0) at crypto/encode_decode/decoder_lib.c:968 #9 0x00007ffff7b039b8 in OSSL_DECODER_from_bio (ctx=0x5555556829e0, in=0x555555682910) at crypto/encode_decode/decoder_lib.c:82 #10 0x00007ffff7d97b9a in file_load_file (ctx=0x55555567b930, object_cb=0x7ffff7cd0aa0 , object_cbarg=0x7fffffffceb8, pw_cb=0x7ffff7b8b2f0 , pw_cbarg=0x55555567bb28) at providers/implementations/storemgmt/file_store.c:534 #11 0x00007ffff7d97675 in file_load (loaderctx=0x55555567b930, object_cb=0x7ffff7cd0aa0 , object_cbarg=0x7fffffffceb8, pw_cb=0x7ffff7b8b2f0 , pw_cbarg=0x55555567bb28) at providers/implementations/storemgmt/file_store.c:700 #12 0x00007ffff7ccd746 in OSSL_STORE_load (ctx=0x55555567bae0) at crypto/store/store_lib.c:432 #13 0x0000555555609ba4 in load_key_certs_crls (uri=0x7fffffffeaec "/home/gowtham/.ssh/id_rsa", format=0, maybe_stdin=0, pass=0x0, desc=0x55555561cbfe "private key", ppkey=0x7fffffffd1a0, ppubkey=0x0, pparams=0x0, pcert=0x0, pcerts=0x0, pcrl=0x0, pcrls=0x0) at apps/lib/apps.c:987 #14 0x000055555560a789 in load_key (uri=0x7fffffffeaec "/home/gowtham/.ssh/id_rsa", format=0, may_stdin=0, pass=0x0, e=0x0, desc=0x55555561cbfe "private key") at apps/lib/apps.c:587 #15 0x00005555555d148c in init_ctx (kdfalg=0x0, pkeysize=0x7fffffffe488, keyfile=0x7fffffffeaec "/home/gowtham/.ssh/id_rsa", keyform=0, key_type=1, passinarg=0x0, pkey_op=1024, e=0x0, engine_impl=0, rawin=0, ppkey=0x7fffffffe4e8, mctx=0x0, digestname=0x0, libctx=0x0, propq=0x0) at apps/pkeyutl.c:548 #16 0x00005555555d0871 in pkeyutl_main (argc=6, argv=0x7fffffffe780) at apps/pkeyutl.c:304 #17 0x00005555555c6491 in do_cmd (prog=0x555555679e60, argc=6, argv=0x7fffffffe780) at apps/openssl.c:418 #18 0x00005555555c60ea in main (argc=6, argv=0x7fffffffe780) at apps/openssl.c:298 // location of id_rsa is found at crypto/bio/bss_mem.c:324 p (char*)((buf_mem_st*)((BIO_BUF_MEM*/FILE*)((BIO*)((file_ctx_st)((OSSL_STORE_CTX *)ctx)->loader_ctx)->_.file.file)->ptr)->(readp/buf))->data $143 = 0x55555568a880 "MIIEpAIBAAKCAQEA7dDtxLPmGkHusoBr7dortWhypPX9nsV4Z6zeXuTl2bT9EuTT\n" p buf_mem->data $293 = 0x55555568b550 "MIIEpAIBAAKCAQEA7dDtxLPmGkHusoBr7dortWhypPX9nsV4Z6zeXuTl2bT9EuTT\nQ9hcuGGmmqlvnqjkhkNaEwzOiR2ExJKoZpT8uu44qrgGQ37agxZFfK8YKGnQlGIu\nxZFqd5e+5RWcP1e0kotsFVKDOUMP1IQFpSJD7ElSS+Y44dDuMne2U44emGGHZ/Lc\n7IZNU" p cin $301 = (OSSL_CORE_BIO *) 0x5555556894f0 // here id_rsa load intention starts #2 0x00007ffff7ccc91a in OSSL_STORE_open_ex (uri=0x7fffffffeaec "/home/gowtham/.ssh/id_rsa", libctx=0x0, propq=0x0, ui_method=0x55555567ca20, ui_data=0x7fffffffd110, params=0x0, post_process=0x0, post_process_data=0x0) at crypto/store/store_lib.c:132 #3 0x0000555555609ac4 in load_key_certs_crls (uri=0x7fffffffeaec "/home/gowtham/.ssh/id_rsa", format=0, maybe_stdin=0, pass=0x0, desc=0x55555561cbfe "private key", ppkey=0x7fffffffd1a0, ppubkey=0x0, pparams=0x0, pcert=0x0, pcerts=0x0, pcrl=0x0, pcrls=0x0) at apps/lib/apps.c:973 #4 0x000055555560a789 in load_key (uri=0x7fffffffeaec "/home/gowtham/.ssh/id_rsa", format=0, may_stdin=0, pass=0x0, e=0x0, desc=0x55555561cbfe "private key") at apps/lib/apps.c:587 #5 0x00005555555d148c in init_ctx (kdfalg=0x0, pkeysize=0x7fffffffe488, keyfile=0x7fffffffeaec "/home/gowtham/.ssh/id_rsa", keyform=0, key_type=1, passinarg=0x0, pkey_op=1024, e=0x0, engine_impl=0, rawin=0, ppkey=0x7fffffffe4e8, mctx=0x0, digestname=0x0, libctx=0x0, propq=0x0) at apps/pkeyutl.c:548 #6 0x00005555555d0871 in pkeyutl_main (argc=6, argv=0x7fffffffe780) at apps/pkeyutl.c:304 #7 0x00005555555c6491 in do_cmd (prog=0x555555679e60, argc=6, argv=0x7fffffffe780) at apps/openssl.c:418 #8 0x00005555555c60ea in main (argc=6, argv=0x7fffffffe780) at apps/openssl.c:298 // crypto/store/store_result.c:87 p *cbdata $270 = (struct ossl_load_result_data_st *) 0x7fffffffceb8 {v = 0x0, (OSSL_STORE_CTX *)ctx = 0x55555567bae0} p *((ossl_load_result_data_st*)((file_load_data_st*)((OSSL_DECODER_CTX*)((decoder_process_data_st*)data)->ctx)->construct_data)->object_cbarg) // crypto/encode_decode/decoder_lib.c:47; ctx also has BIO *in at ctx->construct_data->object_cbarg->ctx->loader_ctx->_.file.file int OSSL_DECODER_from_bio(OSSL_DECODER_CTX *ctx, BIO *in = 0x555555682910) #0 bin2bn (s=0x555555690da3 "(\322\216\220\356\022\234\210\217\002\003\001", len=248, ret=0x555555690c60, endianess=BIG, signedness=UNSIGNED) at crypto/bn/bn_lib.c:500 #1 0x00007ffff7a2525b in BN_bin2bn (s=0x555555690cab "", len=257, ret=0x555555690c60) at crypto/bn/bn_lib.c:523 #2 0x00007ffff79f6609 in bn_ c2i (pval=0x5555556913c8, cont=0x555555690cab "", len=257, utype=2, free_cont=0x7fffffffbc1d "", it=0x7ffff7e7d578 ) at crypto/asn1/x_bignum.c:123 #3 0x00007ffff79efc8b in asn1_ex_c2i (pval=0x5555556913c8, cont=0x555555690cab "", len=257, utype=2, free_cont=0x7fffffffbc1d "", it=0x7ffff7e7d578 ) at crypto/asn1/tasn_dec.c:843 #4 0x00007ffff79eebe4 in asn1_d2i_ex_primitive (pval=0x5555556913c8, in=0x7fffffffbe28, inlen=1185, it=0x7ffff7e7d578 , tag=2, aclass=0, opt=0 '\000', ctx=0x7fffffffc108) at crypto/asn1/tasn_dec.c:818 #5 0x00007ffff79ed5ed in asn1_item_embed_d2i (pval=0x5555556913c8, in=0x7fffffffbe28, len=1185, it=0x7ffff7e7d578 , tag=-1, aclass=0, opt=0 '\000', ctx=0x7fffffffc108, depth=2, libctx=0x0, propq=0x0) at crypto/asn1/tasn_dec.c:217 #6 0x00007ffff79ef65a in asn1_template_noexp_d2i (val=0x5555556913c8, in=0x7fffffffbfe0, len=1185, tt=0x7ffff7ea85e8 , opt=0 '\000', ctx=0x7fffffffc108, depth=1, libctx=0x0, propq=0x0) at crypto/asn1/tasn_dec.c:682 #7 0x00007ffff79ee62b in asn1_template_ex_d2i (val=0x5555556913c8, in=0x7fffffffbfe0, inlen=1185, tt=0x7ffff7ea85e8 , opt=0 '\000', ctx=0x7fffffffc108, depth=1, libctx=0x0, propq=0x0) at crypto/asn1/tasn_dec.c:558 #8 0x00007ffff79edff0 in asn1_item_embed_d2i (pval=0x7fffffffc100, in=0x7fffffffc370, len=1185, it=0x7ffff7ea8398 , tag=16, aclass=0, opt=0 '\000', ctx=0x7fffffffc108, depth=1, libctx=0x0, propq=0x0) at crypto/asn1/tasn_dec.c:422 #9 0x00007ffff79ed242 in asn1_item_ex_d2i_intern (pval=0x7fffffffc100, in=0x7fffffffc370, len=1192, it=0x7ffff7ea8398 , tag=-1, aclass=0, opt=0 '\000', ctx=0x7fffffffc108, libctx=0x0, propq=0x0) at crypto/asn1/tasn_dec.c:118 #10 0x00007ffff79ed2f7 in ASN1_item_d2i_ex (pval=0x7fffffffc100, in=0x7fffffffc370, len=1192, it=0x7ffff7ea8398 , libctx=0x0, propq=0x0) at crypto/asn1/tasn_dec.c:144 #11 0x00007ffff79ed365 in ASN1_item_d2i (pval=0x0, in=0x7fffffffc370, len=1192, it=0x7ffff7ea8398 ) at crypto/asn1/tasn_dec.c:154 #12 0x00007ffff7c83905 in d2i_RSAPrivateKey (a=0x0, in=0x7fffffffc370, len=1192) at crypto/rsa/rsa_asn1.c:116 #13 0x00007ffff7d50cf7 in der2key_decode (vctx=0x555555690320, cin=0x555555690850, selection=135, data_cb=0x7ffff7b03c40 , data_cbarg=0x7fffffffc490, pw_cb=0x7ffff7b8b2f0 , pw_cbarg=0x55555568b0b8) at providers/implementations/encode_decode/decode_der2key.c:219 #14 0x00007ffff7b042f2 in decoder_process (params=0x0, arg=0x7fffffffc5a0) at crypto/encode_decode/decoder_lib.c:968 #15 0x00007ffff7b039b8 in OSSL_DECODER_from_bio (ctx=0x55555568b080, in=0x555555690760) at crypto/encode_decode/decoder_lib.c:82 #16 0x00007ffff7b04533 in OSSL_DECODER_from_data (ctx=0x55555568b080, pdata=0x7fffffffc650, pdata_len=0x7fffffffc648) at crypto/encode_decode/decoder_lib.c:157 #17 0x00007ffff7cd1c1f in try_key_value (data=0x7fffffffc728, ctx=0x55555567bae0, cb=0x7ffff7b8b2f0 , cbarg=0x55555567bb28, libctx=0x7ffff7ed8a20 , propq=0x0) at crypto/store/store_result.c:295 #18 0x00007ffff7cd10a2 in try_key (data=0x7fffffffc728, v=0x7fffffffcea8, ctx=0x55555567bae0, provider=0x555555682360, libctx=0x7ffff7ed8a20 , propq=0x0) at crypto/store/store_result.c:412 #19 0x00007ffff7cd0d5d in ossl_store_handle_load_result (params=0x7fffffffca60, arg=0x7fffffffcea8) at crypto/store/store_result.c:134 #20 0x00007ffff7d98241 in file_load_construct (decoder_inst=0x555555682c00, params=0x7fffffffca60, construct_data=0x7fffffffce00) at providers/implementations/storemgmt/file_store.c:408 #21 0x00007ffff7b03d93 in decoder_process (params=0x7fffffffca60, arg=0x7fffffffcc90) at crypto/encode_decode/decoder_lib.c:743 #22 0x00007ffff7d533b6 in pem2der_decode (vctx=0x5555556890f0, cin=0x5555556894f0, selection=0, data_cb=0x7ffff7b03c40 , data_cbarg=0x7fffffffcc90, pw_cb=0x7ffff7b8b2f0 , pw_cbarg=0x555555682a18) at providers/implementations/encode_decode/decode_pem2der.c:205 #23 0x00007ffff7b042f2 in decoder_process (params=0x0, arg=0x7fffffffcda0) at crypto/encode_decode/decoder_lib.c:968 #24 0x00007ffff7b039b8 in OSSL_DECODER_from_bio (ctx=0x5555556829e0, in=0x555555682910) at crypto/encode_decode/decoder_lib.c:82 #25 0x00007ffff7d97b9a in file_load_file (ctx=0x55555567b930, object_cb=0x7ffff7cd0aa0 , object_cbarg=0x7fffffffcea8, pw_cb=0x7ffff7b8b2f0 , pw_cbarg=0x55555567bb28) at providers/implementations/storemgmt/file_store.c:534 #26 0x00007ffff7d97675 in file_load (loaderctx=0x55555567b930, object_cb=0x7ffff7cd0aa0 , object_cbarg=0x7fffffffcea8, pw_cb=0x7ffff7b8b2f0 , pw_cbarg=0x55555567bb28) at providers/implementations/storemgmt/file_store.c:700 #27 0x00007ffff7ccd746 in OSSL_STORE_load (ctx=0x55555567bae0) at crypto/store/store_lib.c:432 #28 0x0000555555609ba4 in load_key_certs_crls (uri=0x7fffffffeae0 "/home/gowtham/.ssh/id_rsa", format=0, maybe_stdin=0, pass=0x0, desc=0x55555561cbfe "private key", ppkey=0x7fffffffd190, ppubkey=0x0, pparams=0x0, pcert=0x0, pcerts=0x0, pcrl=0x0, pcrls=0x0) at apps/lib/apps.c:987 #29 0x000055555560a789 in load_key (uri=0x7fffffffeae0 "/home/gowtham/.ssh/id_rsa", format=0, may_stdin=0, pass=0x0, e=0x0, desc=0x55555561cbfe "private key") at apps/lib/apps.c:587 #30 0x00005555555d148c in init_ctx (kdfalg=0x0, pkeysize=0x7fffffffe478, keyfile=0x7fffffffeae0 "/home/gowtham/.ssh/id_rsa", keyform=0, key_type=1, passinarg=0x0, pkey_op=1024, e=0x0, engine_impl=0, rawin=0, ppkey=0x7fffffffe4d8, mctx=0x0, digestname=0x0, libctx=0x0, propq=0x0) at apps/pkeyutl.c:548 #31 0x00005555555d0871 in pkeyutl_main (argc=6, argv=0x7fffffffe770) at apps/pkeyutl.c:304 #32 0x00005555555c6491 in do_cmd (prog=0x555555679e60, argc=6, argv=0x7fffffffe770) at apps/openssl.c:418 #33 0x00005555555c60ea in main (argc=6, argv=0x7fffffffe770) at apps/openssl.c:298 *data->ctx={start_input_type = 0x0, input_structure = 0x0, selection = 0, decoder_insts = 0x555555682ba0, construct = 0x7ffff7d98210 , cleanup = 0x7ffff7d98250 , construct_data = 0x7fffffffce00, pwdata = {type = is_ossl_passphrase, _ = {expl_passphrase = {passphrase_copy = 0x7ffff7b8b2f0 "UH\211\345H\203\354\060H\211}\370H\211u\360H\211U\350H\211M\340L\211E\330H\213}\370H\213u\360H\213U\350H\213M\340L\213M\330E1\300\350\310\365\377\377H\203\304\060]\303f\220UH\211\345H\203\354@H\211}\360H\211u\350\211U\344H\307", , passphrase_len = 93824993442600}, pem_password = {password_cb = 0x7ffff7b8b2f0 , password_cbarg = 0x55555567bb28}, ossl_passphrase = {passphrase_cb = 0x7ffff7b8b2f0 , passphrase_cbarg = 0x55555567bb28}, ui_method = {ui_method = 0x7ffff7b8b2f0 , ui_method_data = 0x55555567bb28}}, flag_cache_passphrase = 1, cached_passphrase = 0x0, cached_passphrase_len = 0}} ASN1_item_d2i (pval=0x0, in=0x7fffffffc370, len=1192, it=0x7ffff7ea8398 ) at crypto/asn1/tasn_dec.c:154 p *in $88 = (const unsigned char *) 0x555555690ca0 "0\202\004\244\002\001" #define BN_BYTES 8 struct BIGNUM { unsigned long* d; //array[dmax] int top; //number of words being used <= dmax int dmax; //size of the array d int neg; //1 if negative int flags } LSB is stored in d[0] mmeth $13 = (const RSA_METHOD *) 0x7ffff7ed62e8 (gdb) p &rsa->flags $15 = (int *) 0x555555691444 #0 __memset_avx2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S:284 #1 0x00007ffff7b7ea11 in CRYPTO_zalloc (num=224, file=0x7ffff7de4d4b "crypto/rsa/rsa_lib.c", line=77) at crypto/mem.c:219 #2 0x00007ffff7c87db6 in rsa_new_intern (engine=0x0, libctx=0x0) at crypto/rsa/rsa_lib.c:77 #3 0x00007ffff7c87d80 in RSA_new () at crypto/rsa/rsa_lib.c:36 #4 0x00007ffff7c83a66 in rsa_cb (operation=0, pval=0x7fffffffc110, it=0x7ffff7ea8398 , exarg=0x0) at crypto/rsa/rsa_asn1.c:32 #5 0x00007ffff79f22bb in asn1_item_embed_new (pval=0x7fffffffc110, it=0x7ffff7ea8398 , embed=0, libctx=0x0, propq=0x0) at crypto/asn1/tasn_new.c:126 #6 0x00007ffff79f252f in ossl_asn1_item_ex_new_intern (pval=0x7fffffffc110, it=0x7ffff7ea8398 , libctx=0x0, propq=0x0) at crypto/asn1/tasn_new.c:52 #7 0x00007ffff79edd4f in asn1_item_embed_d2i (pval=0x7fffffffc110, in=0x7fffffffc380, len=1188, it=0x7ffff7ea8398 , tag=16, aclass=0, opt=0 '\000', ctx=0x7fffffffc118, depth=1, libctx=0x0, propq=0x0) at crypto/asn1/tasn_dec.c:366 #8 0x00007ffff79ed242 in asn1_item_ex_d2i_intern (pval=0x7fffffffc110, in=0x7fffffffc380, len=1192, it=0x7ffff7ea8398 , tag=-1, aclass=0, opt=0 '\000', ctx=0x7fffffffc118, libctx=0x0, propq=0x0) at crypto/asn1/tasn_dec.c:118 #9 0x00007ffff79ed2f7 in ASN1_item_d2i_ex (pval=0x7fffffffc110, in=0x7fffffffc380, len=1192, it=0x7ffff7ea8398 , libctx=0x0, propq=0x0) at crypto/asn1/tasn_dec.c:144 #10 0x00007ffff79ed365 in ASN1_item_d2i (pval=0x0, in=0x7fffffffc380, len=1192, it=0x7ffff7ea8398 ) at crypto/asn1/tasn_dec.c:154 #11 0x00007ffff7c83905 in d2i_RSAPrivateKey (a=0x0, in=0x7fffffffc380, len=1192) at crypto/rsa/rsa_asn1.c:116 #12 0x00007ffff7d50cf7 in der2key_decode (vctx=0x555555690320, cin=0x555555690850, selection=135, data_cb=0x7ffff7b03c40 , data_cbarg=0x7fffffffc4a0, pw_cb=0x7ffff7b8b2f0 , pw_cbarg=0x55555568b0b8) at providers/implementations/encode_decode/decode_der2key.c:219 #13 0x00007ffff7b042f2 in decoder_process (params=0x0, arg=0x7fffffffc5b0) at crypto/encode_decode/decoder_lib.c:968 #14 0x00007ffff7b039b8 in OSSL_DECODER_from_bio (ctx=0x55555568b080, in=0x555555690760) at crypto/encode_decode/decoder_lib.c:82 #15 0x00007ffff7b04533 in OSSL_DECODER_from_data (ctx=0x55555568b080, pdata=0x7fffffffc660, pdata_len=0x7fffffffc658) at crypto/encode_decode/decoder_lib.c:157 #16 0x00007ffff7cd1c1f in try_key_value (data=0x7fffffffc738, ctx=0x55555567bae0, cb=0x7ffff7b8b2f0 , cbarg=0x55555567bb28, libctx=0x7ffff7ed8a20 , propq=0x0) at crypto/store/store_result.c:295 #17 0x00007ffff7cd10a2 in try_key (data=0x7fffffffc738, v=0x7fffffffceb8, ctx=0x55555567bae0, provider=0x555555682360, libctx=0x7ffff7ed8a20 , propq=0x0) at crypto/store/store_result.c:412 #18 0x00007ffff7cd0d5d in ossl_store_handle_load_result (params=0x7fffffffca70, arg=0x7fffffffceb8) at crypto/store/store_result.c:134 #19 0x00007ffff7d98241 in file_load_construct (decoder_inst=0x555555682c00, params=0x7fffffffca70, construct_data=0x7fffffffce10) at providers/implementations/storemgmt/file_store.c:408 #20 0x00007ffff7b03d93 in decoder_process (params=0x7fffffffca70, arg=0x7fffffffcca0) at crypto/encode_decode/decoder_lib.c:743 #21 0x00007ffff7d533b6 in pem2der_decode (vctx=0x5555556890f0, cin=0x5555556894f0, selection=0, data_cb=0x7ffff7b03c40 , data_cbarg=0x7fffffffcca0, pw_cb=0x7ffff7b8b2f0 , pw_cbarg=0x555555682a18) at providers/implementations/encode_decode/decode_pem2der.c:205 #22 0x00007ffff7b042f2 in decoder_process (params=0x0, arg=0x7fffffffcdb0) at crypto/encode_decode/decoder_lib.c:968 #23 0x00007ffff7b039b8 in OSSL_DECODER_from_bio (ctx=0x5555556829e0, in=0x555555682910) at crypto/encode_decode/decoder_lib.c:82 #24 0x00007ffff7d97b9a in file_load_file (ctx=0x55555567b930, object_cb=0x7ffff7cd0aa0 , object_cbarg=0x7fffffffceb8, pw_cb=0x7ffff7b8b2f0 , pw_cbarg=0x55555567bb28) at providers/implementations/storemgmt/file_store.c:534 #25 0x00007ffff7d97675 in file_load (loaderctx=0x55555567b930, object_cb=0x7ffff7cd0aa0 , object_cbarg=0x7fffffffceb8, pw_cb=0x7ffff7b8b2f0 , pw_cbarg=0x55555567bb28) at providers/implementations/storemgmt/file_store.c:700 #26 0x00007ffff7ccd746 in OSSL_STORE_load (ctx=0x55555567bae0) at crypto/store/store_lib.c:432 #27 0x0000555555609ba4 in load_key_certs_crls (uri=0x7fffffffeaec "/home/gowtham/.ssh/id_rsa", format=0, maybe_stdin=0, pass=0x0, desc=0x55555561cbfe "private key", ppkey=0x7fffffffd1a0, ppubkey=0x0, pparams=0x0, pcert=0x0, pcerts=0x0, pcrl=0x0, pcrls=0x0) at apps/lib/apps.c:987 #28 0x000055555560a789 in load_key (uri=0x7fffffffeaec "/home/gowtham/.ssh/id_rsa", format=0, may_stdin=0, pass=0x0, e=0x0, desc=0x55555561cbfe "private key") at apps/lib/apps.c:587 #29 0x00005555555d148c in init_ctx (kdfalg=0x0, pkeysize=0x7fffffffe488, keyfile=0x7fffffffeaec "/home/gowtham/.ssh/id_rsa", keyform=0, key_type=1, passinarg=0x0, pkey_op=1024, e=0x0, engine_impl=0, rawin=0, ppkey=0x7fffffffe4e8, mctx=0x0, digestname=0x0, libctx=0x0, propq=0x0) at apps/pkeyutl.c:548 #30 0x00005555555d0871 in pkeyutl_main (argc=6, argv=0x7fffffffe780) at apps/pkeyutl.c:304 #31 0x00005555555c6491 in do_cmd (prog=0x555555679e60, argc=6, argv=0x7fffffffe780) at apps/openssl.c:418 #32 0x00005555555c60ea in main (argc=6, argv=0x7fffffffe780) at apps/openssl.c:298 #0 rsa_init (vprsactx=0x555555690710, vrsa=0x5555556913a0, params=0x0, operation=1024) at providers/implementations/asymciphers/rsa_enc.c:109 #1 0x00007ffff7d2820a in rsa_decrypt_init (vprsactx=0x555555690710, vrsa=0x5555556913a0, params=0x0) at providers/implementations/asymciphers/rsa_enc.c:132 #2 0x00007ffff7b18ef9 in evp_pkey_asym_cipher_init (ctx=0x55555567d4f0, operation=1024, params=0x0) at crypto/evp/asymcipher.c:167 #3 0x00007ffff7b1940e in EVP_PKEY_decrypt_init (ctx=0x55555567d4f0) at crypto/evp/asymcipher.c:261 #4 0x00005555555d1787 in init_ctx (kdfalg=0x0, pkeysize=0x7fffffffe488, keyfile=0x7fffffffeaec "/home/gowtham/.ssh/id_rsa", keyform=0, key_type=1, passinarg=0x0, pkey_op=1024, e=0x0, engine_impl=0, rawin=0, ppkey=0x7fffffffe4e8, mctx=0x0, digestname=0x0, libctx=0x0, propq=0x0) at apps/pkeyutl.c:639 #5 0x00005555555d0871 in pkeyutl_main (argc=6, argv=0x7fffffffe780) at apps/pkeyutl.c:304 #6 0x00005555555c6491 in do_cmd (prog=0x555555679e60, argc=6, argv=0x7fffffffe780) at apps/openssl.c:418 #7 0x00005555555c60ea in main (argc=6, argv=0x7fffffffe780) at apps/openssl.c:298 (gdb) p prsactx->rsa $17 = (RSA *) 0x5555556913a0 (gdb) p &prsactx->rsa $18 = (RSA **) 0x555555690718 # blinding counter measure for the attacks done by measuring the timing of decryption int RSA_blinding_on(RSA *rsa, BN_CTX *ctx); #turns blinding on for key rsa and generates a random blinding factor. ctx is NULL or a preallocated and initialized BN_CTX. void RSA_blinding_off(RSA *rsa); - a random number is stored in (BIGNUM*)((BN_BLINDING*)ret)->mod p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST); crypto/rsa/rsa_ossl.c:643: Montgomery #0 rsa_ossl_private_decrypt (flen=256, from=0x55555568bbd0 "1\367N\215\066\265\"z\266\063\266\353D\025\341\242\241\351naL[\250|\230\277\227\333X\377\v`\204\312\034\037\357\033\330\375\t\233s\307\245\216\203\243]\025E\307\215\071*\205\016\320O\\036\355", to=0x55555566a240 "*\b3", rsa=0x5555556913a0, padding=1) at crypto/rsa/rsa_ossl.c:417 #1 0x00007ffff7c861bc in RSA_private_decrypt (flen=256, from=0x55555568bbd0 "1\367N\215\066\265\"z\266\063\266\353D\025\341\242\241\351naL[\250|\230\277\227\333X\377\v`\204\312\034\037\357\033\330\375\t\233s\307\245\216\203\243]\025E\307\215\071*\205\016\320O\\036\355", to=0x55555566a240 "*\b3", rsa=0x5555556913a0, padding=1) at crypto/rsa/rsa_crpt.c:48 #2 0x00007ffff7d2863e in rsa_decrypt (vprsactx=0x555555690710, out=0x55555566a240 "*\b3", outlen=0x7fffffffe608, outsize=256, in=0x55555568bbd0 "1\367N\215\066\265\"z\266\063\266\353D\025\341\242\241\351naL[\250|\230\277\227\333X\377\v`\204\312\034\037\357\033\330\375\t\233s\307\245\216\203\243]\025E\307\215\071*\205\016\320O\\ 036\355", inlen=256) at providers/implementations/asymciphers/rsa_enc.c:278 #3 0x00007ffff7b195b2 in EVP_PKEY_decrypt (ctx=0x55555567d4f0, out=0x55555566a240 "*\b3", outlen=0x7fffffffe608, in=0x55555568bbd0 "1\367N\215\066\265\"z\266\063\266\353D\025\341\242\241\351naL[\250|\230\277\227\333X\377\v`\204\312\034\037\357\033\330\375\t\233s\307\245\216\203\243]\025E\307\215\071*\205\016\320O\\ 036\355", inlen=256) at crypto/evp/asymcipher.c:290 #4 0x00005555555d1e40 in do_keyop (ctx=0x55555567d4f0, pkey_op=1024, out=0x55555566a240 "*\b3", poutlen=0x7fffffffe608, in=0x55555568bbd0 "1\367N\215\066\265\"z\266\063\266\353D\025\341\242\241\351naL[\250|\230\277\227\333X\377\v`\204\312\034\037\357\033\330\375\t\233s\307\245\216\203\243]\025E\307\215\071*\205\016\320O\\ 036\355", inlen=256) at apps/pkeyutl.c:711 #5 0x00005555555d1178 in pkeyutl_main (argc=7, argv=0x7fffffffe920) at apps/pkeyutl.c:487 #6 0x00005555555c6491 in do_cmd (prog=0x555555679e60, argc=7, argv=0x7fffffffe920) at apps/openssl.c:418 #7 0x00005555555c60ea in main (argc=7, argv=0x7fffffffe920) at apps/openssl.c:298 #0 BN_add (r=0x55555568be28, a=0x55555568be28, b=0x55555568bea0) at crypto/bn/bn_add.c:21 #1 0x00007ffff7a03a24 in bn_mod_inverse_no_branch (in=0x55555568be10, a=0x5555556829e8, n=0x7fffffffd030, ctx=0x55555568bd30, pnoinv=0x7fffffffcfc4) at crypto/bn/bn_gcd.c:143 #2 0x00007ffff7a02f20 in int_bn_mod_inverse (in=0x55555568be10, a=0x5555556829e8, n=0x7fffffffd030, ctx=0x55555568bd30, pnoinv=0x7fffffffcfc4) at crypto/bn/bn_gcd.c:215 #3 0x00007ffff7a03c1b in BN_mod_inverse (in=0x55555568be10, a=0x5555556829e8, n=0x7fffffffd030, ctx=0x55555568bd30) at crypto/bn/bn_gcd.c:530 #4 0x00007ffff7a0b196 in BN_MONT_CTX_set (mont=0x5555556829e0, mod=0x555555690d60, ctx=0x55555568bd30) at crypto/bn/bn_mont.c:349 #5 0x00007ffff7a0b4f5 in BN_MONT_CTX_set_locked (pmont=0x555555691450, lock=0x555555690940, mod=0x555555690d60, ctx=0x55555568bd30) at crypto/bn/bn_mont.c:449 #6 0x00007ffff7c70b4d in rsa_ossl_mod_exp (r0=0x55555568bd98, I=0x55555568bd80, rsa=0x5555556913a0, ctx=0x55555568bd30) at crypto/rsa/rsa_ossl.c:647 #7 0x00007ffff7c7070b in rsa_ossl_private_decrypt (flen=256, from=0x55555568bbd0 "1\367N\215\066\265\"z\266\063\266\353D\025\341\242\241\351naL[\250|\230\277\227\333X\377\v`\204\312\034\037\357\033\330\375\t\233s\307\245\216\203\243]\025E\307\215\071*\205\016\320O\\036\355", to=0x55555566a240 "*\b3", rsa=0x5555556913a0, padding=1) at crypto/rsa/rsa_ossl.c:440 #8 0x00007ffff7c691bc in RSA_private_decrypt (flen=256, from=0x55555568bbd0 "1\367N\215\066\265\"z\266\063\266\353D\025\341\242\241\351naL[\250|\230\277\227\333X\377\v`\204\312\034\037\357\033\330\375\t\233s\307\245\216\203\243]\025E\307\215\071*\205\016\320O\\ 036\355", to=0x55555566a240 "*\b3", rsa=0x5555556913a0, padding=1) at crypto/rsa/rsa_crpt.c:48 #9 0x00007ffff7d0b63e in rsa_decrypt (vprsactx=0x555555690710, out=0x55555566a240 "*\b3", outlen=0x7fffffffe608, outsize=256, in=0x55555568bbd0 "1\367N\215\066\265\"z\266\063\266\353D\025\341\242\241\351naL[\250|\230\277\227\333X\377\v`\204\312\034\037\357\033\330\375\t\233s\307\245\216\203\243]\025E\307\215\071*\205\016\320O\\ 036\355", inlen=256) at providers/implementations/asymciphers/rsa_enc.c:278 #10 0x00007ffff7afc5b2 in EVP_PKEY_decrypt (ctx=0x55555567d4f0, out=0x55555566a240 "*\b3", outlen=0x7fffffffe608, in=0x55555568bbd0 "1\367N\215\066\265\"z\266\063\266\353D\025\341\242\241\351naL[\250|\230\277\227\333X\377\v`\204\312\034\037\357\033\330\375\t\233s\307\245\216\203\243]\025E\307\215\071*\205\016\320O\\ 036\355", inlen=256) at crypto/evp/asymcipher.c:290 #11 0x00005555555d1e40 in do_keyop (ctx=0x55555567d4f0, pkey_op=1024, out=0x55555566a240 "*\b3", poutlen=0x7fffffffe608, in=0x55555568bbd0 "1\367N\215\066\265\"z\266\063\266\353D\025\341\242\241\351naL[\250|\230\277\227\333X\377\v`\204\312\034\037\357\033\330\375\t\233s\307\245\216\203\243]\025E\307\215\071*\205\016\320O\\ 036\355", inlen=256) at apps/pkeyutl.c:711 #12 0x00005555555d1178 in pkeyutl_main (argc=7, argv=0x7fffffffe920) at apps/pkeyutl.c:487 #13 0x00005555555c6491 in do_cmd (prog=0x555555679e60, argc=7, argv=0x7fffffffe920) at apps/openssl.c:418 #14 0x00005555555c60ea in main (argc=7, argv=0x7fffffffe920) at apps/openssl.c:298 [ 2446.458623] bn_cl[87016]: segfault at 10f5dabed0 ip 00007f30422399dd sp 00007f3041320b38 error 6 in libc.so.6[7f30420c1000+195000] [ 2446.458649] Code: 4c 17 f0 c3 66 0f 1f 84 00 00 00 00 00 48 8b 4c 16 f8 48 8b 36 48 89 37 48 89 4c 17 f8 c3 c5 fe 6f 54 16 e0 c5 fe 6f 5c 16 c0 fe 7f 07 c5 fe 7f 4f 20 c5 fe 7f 54 17 e0 c5 fe 7f 5c 17 c0 c5 ``` 8 bin2bn calls at the end of parsing input key 2 bin2bn calls at the end of decrypting. ## convert a number string to BIGNUM ```c++ #include #include int main () { static const char p_str[] = "82019154470699086128524248488673846867876336512717"; BIGNUM *p = BN_new(); BN_dec2bn(&p, p_str); char * number_str = BN_bn2hex(p); printf("%s\n", number_str); OPENSSL_free(number_str); BN_free(p); return 0; } ``` ## RSA-OpenCL ``` bear -- clang -v -ggdb -O0 -o CasRSA_CL CasRSA_CL.c -I/opt/rocm/opencl/include -L/opt/rocm/opencl/lib -lOpenCL bear -- clang++ -v -g -O0 -std=c++14 -DCL_HPP_TARGET_OPENCL_VERSION=120 -DCL_HPP_MINIMUM_OPENCL_VERSION=120 -o CasRSA_CL CasRSA_CL.c -framework OpenCL /mnt/ssd2/RSA-OpenCL/CasRSA_CL /mnt/ssd2/RSA-OpenCL/example_conf.txt /mnt/ssd2/RSA-OpenCL/example_out ``` - BigMultiply gives wrong results if DMAX>32 - Crater localMemSize: 65536 - MI200 localMemSize: 65536 | localName | GPU | localMemSize | |-----------+-------------------------------------+--------------| | Crater | gfx90c:xnack-, 14 | 65536 | | OfcLaptop | gfx90c, 7 | 32768 | | mac | Intel(R) Iris(TM) Graphics 6100, 32 | 65536 | | MI200 | gfx90a:sramecc-:xnack-, 23 | 65536 | | MI100 | gfx908:sramecc+:xnack-, 23 | 65536 | | | | | Workgroup size: 64; operand size: 32uint64(2048) | No. of | CraterGPU | CraterCPU | MI200GPU | MI200CPU | | Mltplctns | (ms) | (ms) | (ms) | (ms) | |-----------+-------------+------------+-------------+------------| | 1 | 0.110206 | 0.005000 | 0.110206 | 0.005000 | | 10 | 0.125635 | 0.009000 | 1.593755 | 0.012000 | | 100 | 0.168636 | 0.112000 | 1.621275 | 0.189000 | | 1000 | 1.641633 | 0.810993 | 2.280635 | 1.250004 | | 10000 | 16.444743 | 9.460168 | 14.260445 | 9.282095 | | 100000 | 160.190304 | 118.011055 | 129.460805 | 98.505699 | | 1000000 | 1548.765934 | 937.301941 | 1228.564619 | 988.374451 | | | | | | | mul dmax:128 global no-barrier 4.4ms. cpu: 0.013ms Workgroup size: 256; operand size: 128uint64(8192) local-bd single-barrier | No. of | CraterGPU | CraterCPU | MI200GPU | MI200CPU | | Muls | (ms) | (ms) | (ms) | (ms) | |--------+-----------+-----------+----------+----------| | 1 | 0.901994 | 0.025000 | 4.707855 | 0.013000 | | 10 | 0.570788 | 0.158000 | 5.790874 | 0.076000 | | 100 | 6.059364 | 0.857000 | 5.873595 | 0.599000 | | 1000 | 11.149769 | 6.577015 | 6.059364 | 0.606000 | | | | | | | Workgroup size: 256; operand-size: 128uint64(8192) local-bd all-barrier | No. of | CraterGPU | CraterCPU | MI200GPU | MI200CPU | | Muls | (ms) | (ms) | (ms) | (ms) | |--------+-------------+-----------+-------------+-----------| | 1 | 0.229468 | 0.007000 | 3.152553 | 0.004000 | | 10 | 0.294830 | 0.047000 | 3.861117 | 0.026000 | | 100 | 0x1.948486 | 0.336000 | 15.829994 | 0.593000 | | 1000 | 0x12.421003 | 3.740000 | 0x35.480863 | 12.162058 | | | | | | | Workgroup size: 256; operand-size: 128uint64(8192) global-bd single-barrier | No. of | CraterGPU | CraterCPU | MI200GPU | MI200CPU | | Muls | (ms) | (ms) | (ms) | (ms) | |--------+-------------+-----------+-------------+----------| | 1 | 0.822065 | 0.014000 | 4.745771 | 0.013000 | | 10 | 0.013000 | 0.136000 | 6.379033 | 0.068000 | | 100 | 0x1.822058 | 0.556000 | 6.418876 | 0.608000 | | 1000 | 0x11.542386 | 6.637050 | 0e22.638486 | 6.104049 | | | | | | | Workgroup size: 256; operand-size: 128uint64(8192) global-bd all-barrier | No. of | CraterGPU | CraterCPU | MI200GPU | MI200CPU | | Muls | (ms) | (ms) | (ms) | (ms) | |--------+-------------+-----------+-------------+----------| | 1000 | 0x13.300202 | 7.151005 | 0x33.553669 | 5.773063 | | | | | | | Workgroup size: 256; operand-size: 128uint64 Q global-bd single-barrier | No. of | CraterGPU | CraterCPU | MI200GPU | MI200CPU | | Muls | (ms) | (ms) | (ms) | (ms) | |--------+--------------+-----------+--------------+------------| | 1 | 1.026363 | 0.011000 | 4.306718 | 0.009000 | | 10 | 0.371134 | 0.059000 | 4.976311 | 0.086000 | | 100 | 33.864186 | 0.564000 | 4.927074 | 2.283000 | | 1000 | 535.070813 | 12.678980 | 1160.624671 | 26.743031 | | 10000 | 43068.482594 | 93.560936 | 12854.556747 | 107.380913 | | | | | | | Workgroup size: 256; operand-size: 256uint64 Q local-bd single-barrier | No. of | CraterGPU | CraterCPU | MI200GPU | MI200CPU | | Muls | (ms) | (ms) | (ms) | (ms) | |--------+--------------+-----------+--------------+------------| | 1 | 8.594990 | 0.076000 | 93.727025 | 0.083000 | | 10 | 8.317500 | 0.182000 | 98.995496 | 0.610000 | | 100 | 0x9.758010 | 1.493999 | 97.843020 | 5.751999 | | 1000 | 0*42.145721 | 15.877095 | 0x102.335580 | 46.226814 | | 10000 | 43068.482594 | 93.560936 | 12854.556747 | 107.380913 | | | | | | | Wavefront size: 64; oprnd-size: 256uint64 local-bd no-barrier | No. of | CraterGPU | CraterCPU | MI200GPU | MI200CPU | | Muls | (ms) | (ms) | (ms) | (ms) | |---------+-------------+-------------+-------------+-------------| | 1 | 2.626724 | 0.063000 | 40.560034 | 0.048000 | | 10 | 2.936132 | 0.398000 | 42.006628 | 0.452000 | | 100 | 3.566997 | 2.544002 | 41.582654 | 5.420998 | | 1000 | 14.316332 | 16.191063 | 58.592075 | 48.733883 | | 10000 | 128.633843 | 200.935287 | 370.545788 | 222.183701 | | 100000 | 1278.278979 | 1627.688599 | 3535.567641 | 1985.583252 | | 1000000 | 0*Mem | 0*Mem | 0*Mem | 0*Mem | | | | | | | 0x: incorrect results 0y: incorrect results occassionally 43, 46,47, 51 52 54 59 75 96 98 mac fails at DMAX==32 256 1000 barrier 59 ms atom 53 ms ### decryptOnCrater DMAX: 2 | No. of | CraterGPU | CraterCPU | MI200GPU | MI200CPU | | Decrypts | (ms) | (ms) | (ms) | (ms) | |----------+-----------+-------------+-------------+-------------| | 1 | 0.036803 | 0.063000 | 40.560034 | 0.048000 | | 10 | 0.036847 | 0.398000 | 42.006628 | 0.452000 | | 100 | 0.054819 | 2.544002 | 41.582654 | 5.420998 | | 1000 | 0.255681 | 16.191063 | 58.592075 | 48.733883 | | 10000 | 2.303482 | 200.935287 | 370.545788 | 222.183701 | | 100000 | 22.775459 | 1627.688599 | 3535.567641 | 1985.583252 | DMAX: 4 | No. of | CraterGPU | CraterCPU | MI200GPU | MI200CPU | | Decrypts | (ms) | (ms) | (ms) | (ms) | |----------+-----------+-------------+------------+-------------| | 1 | 0.036803 | 0.063000 | 40.560034 | 0.048000 | | 10 | 0.036847 | 0.398000 | 42.006628 | 0.452000 | | 100 | 0.054819 | 2.544002 | 41.582654 | 5.420998 | | 1000 | 0.255681 | 16.191063 | 58.592075 | 48.733883 | | - 10000 | 2.303482 | 200.935287 | 370.545788 | 222.183701 | | 100000 | 55.182907 | 1627.688599 | 165.136606 | 1985.583252 | DMAX: 64 | No. of | CraterGPU | CraterCPU | MI200GPU | MI200CPU | | Decrypts | (ms) | (ms) | (ms) | (ms) | |----------+-----------+-----------+----------+----------| | 1 | 3.0 | 4.5 | 71.2 | 4.5 | | 10 | 3.0 | 45.0 | 71.2 | 45.0 | | 100 | 9.6 | 450.7 | 71.2 | 450.7 | | | 49x0 | | | | | 1000 | 75.5 | 4507.5 | 261.6 | 4507.5 | | | 49x0 | | 312x0 | | | 10000 | 738.3 | 45075.2 | 1935.0 | 45075.2 | | | 49x0 | | | | | 100000 | 7370.8 | 450752.8 | 17874.7 | 450752.8 | | | 49x0 | | | | | | | | | | DMAX: 64 encrypt | No. of | CraterGPU | CraterCPU | MI200GPU | MI200CPU | | Decrypts | (ms) | (ms) | (ms) | (ms) | |----------+-----------+-----------+----------+----------| | 1 | 353.2x | 4.5 | 71.2 | 4.5 | | 10 | 3.0x | 45.0 | 71.2 | 45.0 | | 100 | 9.6x | 450.7 | 71.2 | 450.7 | | | 49x0x | | | | | 1000 | 70.3 | 4507.5 | 227.7 | 4507.5 | | 10000 | 669.3 | 45075.2 | 1713.2 | 45075.2 | | | 49x0x | | | | | 100000 | 7370.8x | 450752.8 | 17874.7 | 450752.8 | | | 49x0x | | | | DMAX: 64 decrypt | No. of | CraterGPU | CraterCPU | MI200GPU | MI200CPU | | Decrypts | (ms) | (ms) | (ms) | (ms) | |----------+-----------+-----------+----------+----------| | 1 | 353.2x | 4.5 | 71.2 | 4.5 | | 10 | 3.0x | 45.0 | 71.2 | 45.0 | | 100 | 35.8 | 450.7 | 35.8 | 450.7 | | 1000 | 8732.6 | 4507.5 | 28984.2 | 4507.5 | | 10000 | 85108.4 | 45075.2 | 214601.9 | 45075.2 | | 100000 | 7370.8x | 450752.8 | 17874.7 | 450752.8 | | | 49x0x | | | | # TLS (TransportLayerSecurity) ## HKDF (Hashed Key Derivation Function) ### HMAC (Hash-based Message Authentication Code) ## AES-GCM Advanced Encryption Standard in Galois/Counter Mode