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.
For example, for generating aes_p8_set_encrypt_key
in crypto/aes/build.info
:
GENERATE[aesp8-ppc.s]=asm/aesp8-ppc.pl $(PERLASM_SCHEME)
for generating OPENSSL_madd300_probe
in crypto/build.info
:
GENERATE[ppccpuid.s]=ppccpuid.pl $(PERLASM_SCHEME)
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
Followed with :
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) $@
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.
The assembly language file is generated with a xlat program. For the Power8 gear the file is
ppc-xlate.pl
in theperlasm
directory. It is used byaesp8-ppc.pl
in thecrypto/aes/asm
directory.Here is how you translate it. I'm working from GCC112 on the compile farm, which is ppc64le.
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).The second argument to
aesp8-ppc.pl
is calledflavor
. It isppc64le
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.Once you have
aesp8-ppc.s
you can compile and assemble the source file with GCC.And then:
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.You are interested in the four functions
aes_p8_set_encrypt_key
,aes_p8_set_decrypt_key
,aes_p8_encrypt
andaes_p8_decrypt
.I'll help you with the first one:
aes_p8_set_encrypt_key
.Lather, rinse, repeat for
AES_KEY
,aes_p8_set_decrypt_key
,aes_p8_encrypt
andaes_p8_decrypt
.Eventually you will end up with a header like shown in Cryptogams | AES on the OpenSSL wiki. Cryptogams | AES is written for ARMv4 but the same applies to Power8 as well.
Stepping back a bit, you are using the Cryptogams implementation of AES on Power8. Cryptogams is Andy Polyakov's project to provide high speed cryptography to other developers.
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's public source is at GitHub | dot-asm. Unfortunately, most of Andy's work has not been uploaded so you have to pull it from OpenSSL. And more unfortunate, none of it is documented so you have to do a fair amount of poking and prodding in the OpenSSL sources.
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.
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.
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.