如何从OpenSSL中的perl脚本生成程序集文件 [英] How the assembly file is generated from the perl script in OpenSSL

查看:130
本文介绍了如何从OpenSSL中的perl脚本生成程序集文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OpenSSL(版本1.1.0e)的开源代码中,我看到一些函数定义是由文件夹内的perl文件生成的. 在加密货币内每个文件夹中存在的build.info文件中,他们编写了几行代码以从相应的.pl生成.s.

In the opensource code of OpenSSL(version 1.1.0e) I saw that some of the function definition is generated by the perl files present inside the folders. In the build.info file present in each folders inside the crypto, they have written some lines to generate the .s from the corresponding .pl.

例如,用于在crypto/aes/build.info中生成aes_p8_set_encrypt_key:

GENERATE[aesp8-ppc.s]=asm/aesp8-ppc.pl $(PERLASM_SCHEME)

用于在crypto/build.info中生成OPENSSL_madd300_probe:

GENERATE[ppccpuid.s]=ppccpuid.pl $(PERLASM_SCHEME)

在主Makefile(生成的makefile)中也有几行,如下所示:

And also in the main Makefile(generated makefile), there are some lines as below:

crypto/aes/aes-x86_64.o: crypto/aes/aes-x86_64.s
$(CC)  -I. -Icrypto/include -Iinclude $(CFLAGS) $(LIB_CFLAGS) -MMD -MF crypto/aes/aes-x86_64.d.tmp -MT $@ -c -o $@ crypto/aes/aes-x86_64.s
@touch crypto/aes/aes-x86_64.d.tmp
@if cmp crypto/aes/aes-x86_64.d.tmp crypto/aes/aes-x86_64.d > /dev/null 2> /dev/null; then \
    rm -f crypto/aes/aes-x86_64.d.tmp; \
else \
    mv crypto/aes/aes-x86_64.d.tmp crypto/aes/aes-x86_64.d; \
fi

后跟:

crypto/aes/aes-x86_64.s: crypto/aes/asm/aes-x86_64.pl
CC="$(CC)" $(PERL) crypto/aes/asm/aes-x86_64.pl $(PERLASM_SCHEME) $@

任何人都可以解释如何从.pl文件生成.s吗? 我需要将它们添加到我的项目内的Makefile中,以解决其定义是由.pl文件生成的函数的undefined reference错误.

Can anyone explain how the .s is generated from the .pl files? I need to add them in my Makefile inside my project, to solve the undefined reference error coming for the functions whose definition is generated by the .pl file.

推荐答案

如何从OpenSSL中的Perl脚本生成程序集文件...

How the assembly file is generated from the Perl script in OpenSSL...

您正在Power8上使用AES的 Cryptogams实现. Cryptogams是Andy Polyakov的项目,旨在为其他开发人员提供高速加密技术.

You are using the Cryptogams implementation of AES on Power8. Cryptogams is Andy Polyakov's project to provide high speed cryptography to other developers.

汇编语言文件是使用xlat程序生成的.对于Power8齿轮,文件为 ppc-xlate.pl >目录.它由crypto/aes/asm中的 aesp8-ppc.pl 使用.目录.

The assembly language file is generated with a xlat program. For the Power8 gear the file is ppc-xlate.pl in the perlasm directory. It is used by aesp8-ppc.pl in the crypto/aes/asm directory.

这是您如何翻译它.我正在使用编译场上的GCC112 ,即ppc64le.

Here is how you translate it. I'm working from GCC112 on the compile farm, which is ppc64le.

git clone https://github.com/openssl/openssl.git
mkdir cryptogams

cp ./openssl/crypto/perlasm/ppc-xlate.pl cryptogams/
cp ./openssl/crypto/aes/asm/aesp8-ppc.pl cryptogams/

cd cryptogams/
chmod +x *.pl

./aesp8-ppc.pl ppc64le aesp8-ppc.s

aesp8-ppc.pl会生成纯汇编语言源文件,因此请在输出文件上加上小写的*.s.有时,翻译中包含C预处理程序语句,并且它需要很大的*.S(但在这种情况下不是).

aesp8-ppc.pl generates a pure assembly language source file so name the output file with the little *.s. Sometimes the translation includes C preprocessor statements and it needs a big *.S (but not in this case).

aesp8-ppc.pl的第二个参数称为flavor.在上面的命令中为ppc64le.风味有两件事.首先,它选择32位或64位.其次,它选择little-endian或big-endian.确保口味正确.

The second argument to aesp8-ppc.pl is called flavor. It is ppc64le in the commands above. Flavor does two things. First, it selects either 32-bit or 64-bit. Second, it selects either little-endian or big-endian. Be sure to get the flavor right.

根据 ppc8不能基于powerpc64 big-endian 的Andy的说法. ,大端PowerPC应该使用linux64,而不是linux64be.小尾数需要linux64le.

According to Andy at ppc8 does not build on powerpc64 big-endian, big-endian PowerPC should use linux64, not linux64be. Little-endian needs linux64le, however.

一旦拥有aesp8-ppc.s,就可以使用GCC编译和汇编源文件.

Once you have aesp8-ppc.s you can compile and assemble the source file with GCC.

gcc -mcpu=power8 -c aesp8-ppc.s

然后:

$ objdump --disassemble aesp8-ppc.o
aesp8-ppc.o:     file format elf64-powerpcle
...

0000000000000420 <aes_p8_set_decrypt_key>:
     420:       c1 ff 21 f8     stdu    r1,-64(r1)
     424:       a6 02 48 7d     mflr    r10
     428:       50 00 41 f9     std     r10,80(r1)
     42c:       75 fc ff 4b     bl      a0 <aes_p8_set_encrypt_key>
     430:       a6 03 48 7d     mtlr    r10
     434:       00 00 03 2c     cmpwi   r3,0
     438:       68 00 c2 40     bne-    4a0 <Ldec_key_abort>
     43c:       36 20 07 55     rlwinm  r7,r8,4,0,27
     440:       10 ff 65 38     addi    r3,r5,-240
     444:       7e f8 08 55     rlwinm  r8,r8,31,1,31
     448:       14 3a a3 7c     add     r5,r3,r7
     44c:       a6 03 09 7d     mtctr   r8
...

这时您已经有了一个目标文件,但是您不知道API签名或如何使用它.要找出下一步该怎么做,您必须先objdump,然后grep OpenSSL源代码以查看其使用方式.

At this point you have an object file, but you don't know the API signatures or how to use it. To find out what to do next you have to objdump and then grep the OpenSSL sources to see how they use it.

$ nm aesp8-ppc.o | grep ' T '
00000000000006c0 T aes_p8_cbc_encrypt
0000000000001140 T aes_p8_ctr32_encrypt_blocks
00000000000005c0 T aes_p8_decrypt
00000000000004c0 T aes_p8_encrypt
0000000000000420 T aes_p8_set_decrypt_key
00000000000000a0 T aes_p8_set_encrypt_key
0000000000001d00 T aes_p8_xts_decrypt
0000000000001a60 T aes_p8_xts_encrypt

您对四个功能aes_p8_set_encrypt_keyaes_p8_set_decrypt_keyaes_p8_encryptaes_p8_decrypt感兴趣.您将使用找到的签名为程序创建头文件.

You are interested in the four functions aes_p8_set_encrypt_key, aes_p8_set_decrypt_key, aes_p8_encrypt and aes_p8_decrypt. You will use the signatures you find to create a header file for your program.

我将为您提供第一个帮助:aes_p8_set_encrypt_key.

I'll help you with the first one: aes_p8_set_encrypt_key.

$ cd openssl

# Find aes_p8_set_encrypt_key
$ grep -nIR aes_p8_set_encrypt_key
crypto/evp/e_aes.c:153:# define HWAES_set_encrypt_key aes_p8_set_encrypt_key

# Now look for HWAES_set_encrypt_key
$ grep -nIR HWAES_set_encrypt_key
...
crypto/evp/e_aes.c:2515:int HWAES_set_encrypt_key(const unsigned char *userKey, const int bits,
...

# Now find the complete HWAES_set_encrypt_key
$ cat -n crypto/evp/e_aes.c
...
  2515  int HWAES_set_encrypt_key(const unsigned char *userKey, const int bits,
  2516                            AES_KEY *key);

起泡,冲洗,然后重复AES_KEYaes_p8_set_decrypt_keyaes_p8_encryptaes_p8_decrypt.

Lather, rinse, repeat for AES_KEY, aes_p8_set_decrypt_key, aes_p8_encrypt and aes_p8_decrypt.

最终,您将得到一个标题,如 Cryptogams |中所示. AES Cryptogams | OpenSSL Wiki上的SHA . Cryptogams | AES Cryptogams | SHA 是为ARMv4编写的,但Power8也是如此.

Eventually you will end up with a header like shown in Cryptogams | AES or Cryptogams | SHA on the OpenSSL wiki. Cryptogams | AES and Cryptogams | SHA are written for ARMv4 but the same applies to Power8 as well.

安迪双重许可他的工作.一种许可证是OpenSSL许可证,因为Andy适用于OpenSSL.第二个许可证是不具有OpenSSL限制的BSD样式许可证.

Andy dual licenses his work. One license is the OpenSSL license because Andy works for OpenSSL. The second license is a BSD style license that does not have the encumbrances of OpenSSL.

Andy的公共资源位于 GitHub | dot-asm .不幸的是,Andy的许多工作尚未上传,因此您必须将其从OpenSSL中删除.而且很多地方都没有记载,因此您必须在OpenSSL来源中进行大量的戳探和探测.

Andy's public source is at GitHub | dot-asm. Unfortunately, a lot of Andy's work has not been uploaded so you have to pull it from OpenSSL. And a lot it is not documented so you have to do a fair amount of poking and prodding in the OpenSSL sources.

据我所知,您可以在两个地方查找有关使用Cryptogams和Power8加密技术的文档.首先是OpenSSL Wiki页面 Cryptogams | AES Cryptogams | SHA .这些教程是ARMv4,但它也适用于Power 8.我写了Wiki文章,所以错误和遗漏是我的错误.

As far as I know there are two places you can look for documentation on using Cryptogams and Power8 cryptography. First is the OpenSSL wiki pages Cryptogams | AES and Cryptogams | SHA. The tutorials are ARMv4 but it applies to Power 8, too. I wrote the wiki articles so errors and omissions are my mistakes.

第二个要看的地方是GitHub和 Noloader | POWER8加密货币.我帮助维护Crypto ++,而POWER8加密书是我的知识堆. POWER8本书在第7章中包括用于PowerPC的Cryptogams SHA.

The second place to look is GitHub and Noloader | POWER8 crypto. I help maintain Crypto++ and the POWER8 crypto book is my knowledge dump. The POWER8 book includes Cryptogams SHA for PowerPC in Chapter 7.

POWER8加密书由Bill Schmidt和我撰写,因为在Power8上使用AES和SHA时我们找不到文档.比尔·施密特(Bill Schmidt)为IBM工作,甚至他都无法获得文档.我们所能找到的只是一个IBM工程师的博客文章,而该文章严重缺少细节.

The POWER8 crypto book was written by Bill Schmidt and I because we could not find documentation when working with AES and SHA on Power8. Bill Schmidt works for IBM and even he could not get the docs. All we could find was a blog post from an IBM engineer that was grossly missing details.

这篇关于如何从OpenSSL中的perl脚本生成程序集文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆