2

Background:I am working on an encryption application, i have the app written in Objective C and now i want to rewrite it in pascal so that it runs on windows. I am using pascal as it is a language i already know and lazarus as it is a free IDE

Question: How do i use the BigNum module from openSSL in lazarus, i have downloaded this unit: http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/packages/openssl/src/

and i've put it in uses openssl;

However when i try and declare a BIGNUM

procedure Tform3.Button1Click(Sender: TObject);
var bits:integer;
    p:BIGNUM;
begin
   bits:=512;

   p:=BN_new();
   BN_generate_prime(p, bits, FALSE, NULL, NULL, NULL, NULL);

end;  

I just get an error: Error: Identifier not found "BIGNUM"

How do i use the BigNum module and the BN_generate prime(module)?

ain
  • 22,394
  • 3
  • 54
  • 74
Tawfiqh
  • 143
  • 1
  • 10
  • The code you link to does not include a type called `BIGNUM`. There is one called `PBIGNUM`. There is no function `BN_new` and no function `BN_generate prime`. Since you have the source yourself, you could have simply used the find facility of the IDE (or any text editor) to diagnose that yourself. – David Heffernan Sep 03 '11 at 11:27
  • Thanks that answers the first part of my question but i still can't find a way of using BN_generate_prime or an equivalent. – Tawfiqh Sep 03 '11 at 11:41
  • Why don't you compile your objective C code on windows with mingw: http://stackoverflow.com/questions/56708/objective-c-for-windows – David Heffernan Sep 03 '11 at 11:52
  • @David: many of the good things for Objective-C are only available on the Apple platforms. I doubt they can be found in MingW's GNU Obj-C compiler. – Rudy Velthuis Sep 03 '11 at 14:41
  • @Rudy The encryption code would likely be fine – David Heffernan Sep 03 '11 at 14:49
  • @David: Sure, but not the rest of the program. – Rudy Velthuis Sep 03 '11 at 15:05
  • @Rudy Well, link it in through a DLL or using $L. It was only the other day that you made the exact same recommendation! – David Heffernan Sep 03 '11 at 15:09
  • @David: Much eaiser to use libeay32.dll, I guess. The openssl.pas file does not completely convert all functions. – Rudy Velthuis Sep 03 '11 at 15:38
  • And don't forget to submit a bug, or better a patch. Header improvements can probably still make the upcoming 2.6.0 – Marco van de Voort Sep 06 '11 at 12:36

1 Answers1

4

The unit you are using is an import unit for three DLLs, and one of them is libeay32.dll. But unfortunately, it does not fully import all functions from libeay32.dll. It omits, for instance, the BIGNUM part, i.e. what you are looking for.

Perhaps you can find a better import unit, like this unit called libeay32.pas, which seems to have all the BN_ functions or you can get the header from this link and add the missing functions to openssl.pas. That is not trivial, but also not undoable. I would go for the ready translated unit. It looks good. The website seems to have a few more things you might need.

Rudy Velthuis
  • 28,387
  • 5
  • 46
  • 94
  • The unit generates this error: 'libeay32.pas(275,5) Error: Compile time expression: Wanted STRING but got INTEGER at "COMPILERVERSION >= 20"' on line 275: '{$IF CompilerVersion >= 20}' – Tawfiqh Sep 03 '11 at 19:21
  • 1
    that's because you are using FreePascal rather than delphi. Just hack out enough of the unit to call the couple of functions you need. – David Heffernan Sep 03 '11 at 22:13
  • @Tawfiqh: Probably the line can simply be commented out. Also comment out the $IFEND that belongs to it. – Rudy Velthuis Sep 03 '11 at 22:35
  • The decent way is to put it under {$ifndef FPC} if it tests Delphi specific conditionals (like versions). Don't forget to enable Delphi mode too – Marco van de Voort Sep 04 '11 at 09:26
  • @Marco: sure, but that assumes the user of the unit actually knows the differences between Delphi and FPC and how they should be encountered. – Rudy Velthuis Sep 04 '11 at 12:07