Plugin questions and troubleshooting

Jason Dufair jase at dufair.org
Fri May 21 16:16:23 UTC 2004


Thanks to Ned Konz's excellent documentation on building the Spread
plugin and some prior experience hacking the Mpeg3Plugin, I'm making
some sort of headway developing the OpenSSLPlugin.

With the Win32 VM toolkit, I am able to compile and successfully run a
plain ol' C program that calls 2 functions in the OpenSSL dll and
encrypts/decrypts a couple of arrays of unsigned chars with AES
(Rijndael) in CBC mode.  I put that aside and created an OpenSSLPlugin
class as a subclass of SmartSyntaxInterpreterPlugin.  I have 4
parameters: plaintext, ciphertext, key, and iv (initialization vector),
all ByteArrays, that I pass into the (Slang) primitive.  In the
primitive and call a C function that takes pointers to each of these and
puts the encrypted bytes into the ciphertext array.  I then have a test
class with a method that declares 4 ByteArrays of 16 bytes and a method
that calls the primitive with these.  Below are the 3 pertinent methods
if anyone is kind enough to look at them.  I can generate my code ok
with VMMaker and everything seems to compile and link ok, both as
internal and external plugins without any warnings about any of my code.

I have a few questions:

1) Ragnar suggested I load the OpenSSL dll/so using dlopen() instead of
   compiling with the OpenSSL .h file and linking to the dll/so.  I'm
   actually doing it the latter way, but am inclined to switch to the
   former way as it seems it would be easier to port to other platforms
   (currently developing on Win32 and plan on porting to Linux).  Also
   with the "compile with header file and link" method, I have to hack
   the main makefile and create an OpenSSL-specific Makefile (like the
   Mpeg3Plugin does) and I'd rather avoid this ugliness if possible.
   Any suggestions in this area?

2) It appears that my plugin isn't loading properly somehow.  When I
   compile it as an external plugin, the Smalltalk code after the
   <primitive...> call executes (i.e. something fails, primitive-wise).
   When I compile it as an internal plugin, the VM won't start (I get a
   dialog box about the application failing to initialize).  Does anyone
   have suggestions on how to troubleshoot this?

3) Does anything below look particularly egregious?  I'm I at least on
   the right track?

If you got this far, thanks for taking the time to look at this and help
me with it.  I plan on, at least, making all of the symmetric and public
key algorithms in OpenSSL available via primitives and a lovely (set of)
Smalltalk classes.

-----
testAES

	| plaintext ciphertext key iv |
	key := (0 to: 15) asByteArray.
	plaintext := (0 to: 15) asByteArray.
	ciphertext := ByteArray new: 16.
	iv := ByteArray new: 16.
	self primTestAes: plaintext ciphertext: ciphertext key: key iv: iv.
	self assert: ciphertext hex =
	'0A940BB5416EF045F1C39458C653EA5A'.

primTestAes: plaintext ciphertext: ciphertext key: key iv: iv

	<primitive: 'primitiveAESEncryptCBC' module: 'OpenSSLPlugin'>
	self halt.

primitiveAESEncryptCBC: plaintext ciphertext: ciphertext key: aKey iv: anInitializationVector
	"Encrypt aByteArray using the AES (Rijndael) algorithm in CBC mode"

	| aesKey |
	self cCode: '' inSmalltalk: [aesKey := nil. aesKey].

	self var: #aesKey type: 'AES_KEY'.

	self primitive: 'primitiveAESEncryptCBC' parameters: #(#ByteArray #ByteArray #ByteArray #ByteArray).
	self cCode: 'AES_set_encrypt_key(aKey, 128, &aesKey)'.
	self cCode: 'AES_cbc_encrypt(plaintext, ciphertext, 16, &aesKey, anInitializationVector, AES_ENCRYPT)'.
	self cCode: 'printf("%X %X %X %X", ciphertext[0], ciphertext[1],
	ciphertext[2], ciphertext[3])'

-- 
Jason Dufair - jase at dufair.org
http://www.dufair.org/
"Nobody gets a lifetime rehearsal
As specks of dust, we're universal"
-- Indigo Girls




More information about the Squeak-dev mailing list