DCIT / perl-CryptX

https://metacpan.org/pod/CryptX
Other
35 stars 23 forks source link

HP-UX 11.11 C-ANSI-C has no stdint.h #43

Closed Tux closed 6 years ago

Tux commented 6 years ago

By the time these archaic systems were still modern, stdint.h did not exist on HP-UX

I created src/ltm/stdint.h:

#define MP_32BIT

(MP_64BIT caused epic failures)

HP-UX 11.11/64 U  rp3410/64 PA8800/800
This is perl 5, version 14, subversion 2 (v5.14.2) built for PA-RISC2.0-LP64

With above define, I saw

All tests successful.
Files=134, Tests=29513, 407 wallclock secs (15.24 usr  0.95 sys + 318.28 cusr  6.44 csys = 340.91 CPU)
Result: PASS
Tux commented 6 years ago

on HP-UX 11.31 building with HP C-ANSI-C in 64bitall mode, I needed

#define MP_64BIT

and

wgrep __hpux src/ltm/tommath.h
src/ltm/tommath.h:   90 ===
#      error You must not define DIGIT_BIT when using MP_16BIT
#   endif
#elif defined(MP_64BIT)
/* for GCC only on supported platforms */
typedef uint64_t mp_digit;
#   if defined(__GNUC__) || defined(__hpux)
typedef unsigned long        mp_word __attribute__((mode(TI)));
#   else
/* it seems you have a problem
 * but we assume you can somewhere define your own uint128_t */
typedef uint128_t            mp_word;

Furthermore, the #defines in ltc/headers/tomcrypt_custom.h are not dynamic, causing havoc if methods are not available. ON this system I had to #undef LTC_RC4, LTC_CHACHA20, LTC_YARROW, LTC_FORTUNA, and LTC_SOBER128, after which all tests fail :(

/usr/lib/hpux64/dld.so: Unsatisfied data symbol 'yarrow_desc' in load module '/home/merijn/.cpan/build/CryptX-0.060-0/blib/arch/auto/CryptX/CryptX.so'.
/usr/lib/hpux64/dld.so: Unsatisfied data symbol 'fortuna_desc' in load module '/home/merijn/.cpan/build/CryptX-0.060-0/blib/arch/auto/CryptX/CryptX.so'.
/usr/lib/hpux64/dld.so: Unsatisfied data symbol 'rc4_desc' in load module '/home/merijn/.cpan/build/CryptX-0.060-0/blib/arch/auto/CryptX/CryptX.so'.
/usr/lib/hpux64/dld.so: Unsatisfied data symbol 'chacha20_prng_desc' in load module '/home/merijn/.cpan/build/CryptX-0.060-0/blib/arch/auto/CryptX/CryptX.so'.
/usr/lib/hpux64/dld.so: Unsatisfied data symbol 'sober128_desc' in load module '/home/merijn/.cpan/build/CryptX-0.060-0/blib/arch/auto/CryptX/CryptX.so'.
Can't load '/home/merijn/.cpan/build/CryptX-0.060-0/blib/arch/auto/CryptX/CryptX.so' for module CryptX: Unresolved external at /pro/lib/perl5/5.26.2/IA64.ARCHREV_0-thread-multi-LP64-ld/DynaLoader.pm line 194.
karel-m commented 6 years ago

Hi I have still an access to p5p-hpux.procura.nl (you have granted to me) can I reproduce it there?

Ad stdint.h do you know of any handy #ifdef to detect the situation when we do not have stdint.h on HP/UX?

Tux commented 6 years ago

You still have access to that box. However, it is a PA-RISC2 , not a Itanium. I hope to be able to add Itanium to that network segment, but I need the management to grant me an oké, as they don't want to pay for the electricity

Tux commented 6 years ago

FWIW I need CryptX for Spreadsheet::ParseXLSX, which I use a lot.

karel-m commented 6 years ago

I have just uploaded CryptX-0.060_001 can you test it?

http://cpan.metacpan.org/authors/id/M/MI/MIK/CryptX-0.060_001.tar.gz

Tux commented 6 years ago

No manual changes made

cc -Iltm -Iltc/headers -DLTC_SOURCE -DLTC_NO_TEST -DLTC_NO_PROTOTYPES -DLTM_DESC -D_POSIX_C_SOURCE=199506L -D_REENTRANT -Ae -DPERL_DONT_CREATE_GVSV +Z -z -D_HPUX_SOURCE -Wl,+vnocompatwarnings +DD64 -I/pro/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  +Z +O2 +Onolimit -c ltc/prngs/chacha20.c -o ltc/prngs/chacha20.o
"ltc/headers/tomcrypt_prng.h", line 76: warning #2040-D: expected an identifier
     };
      ^

"ltc/prngs/chacha20.c", line 41: error #2136: struct "<unnamed>" has no field
          "chacha"
     XMEMSET(&prng->chacha.ent, 0, sizeof(prng->chacha.ent));
                    ^
karel-m commented 6 years ago

It looks like the compiler does not like a struct containing an anonymous union like:

typedef struct {
   union {
      char dummy[1];
      struct yarrow_prng    yarrow;
      struct rc4_prng       rc4;
      struct chacha20_prng  chacha;
      struct fortuna_prng   fortuna;
      struct sober128_prng  sober128;
   };
   short ready;
} prng_state;
Tux commented 6 years ago

https://www.geeksforgeeks.org/g-fact-38-anonymous-union-and-structure/ https://stackoverflow.com/questions/3228104/anonymous-union-within-struct-not-in-c99 "Anonymous unions are a GNU extension, not part of any standard version of the C language. You can use -std=gnu99 or something like that for c99+GNU extensions, but it's best to write proper C and not rely on extensions which provide nothing but syntactic sugar...

Edit: Anonymous unions were added in C11, so they are now a standard part of the language. Presumably GCC's -std=c11 lets you use them." Added in gcc-2.95: https://gcc.gnu.org/ml/gcc-patches/1999-06n/msg00376.html

Tux commented 6 years ago

Surprisingly, AIX' xlc accepts this code style. Note that perl itself requires C89 (not even C99), so declaring C11 should not be an option IMHO.

All tests successful.
Files=134, Tests=29513, 112 wallclock secs ( 7.03 usr  0.51 sys + 99.72 cusr  2.55 csys = 109.81 CPU)
Result: PASS
karel-m commented 6 years ago

@sjaeckel what do you think about this libtomcrypt related change to avoid the use of anonymous union https://github.com/DCIT/perl-CryptX/commit/e038ed05c86b081a3ad20503571a46bacaf4fb8c ?

karel-m commented 6 years ago

@Tux could you try http://cpan.metacpan.org/authors/id/M/MI/MIK/CryptX-0.060_002.tar.gz ?

karel-m commented 6 years ago

@sjaeckel or do you prefer an alternative approach proposed by @Tux https://github.com/DCIT/perl-CryptX/pull/44/commits/c5a9061055b775d8b3928debb71216f5fdc7fced ?

Tux commented 6 years ago

@karel-m @sjaeckel Karel's patch also works fine:

Files=134, Tests=29513, 121 wallclock secs ( 5.76 usr  1.07 sys + 111.89 cusr  6.53 csys = 125.25 CPU)
Result: PASS
karel-m commented 6 years ago

@sjaeckel ping - c5a9061 or e038ed0 ?

sjaeckel commented 6 years ago

sorry for the delay! c5a9061055b775d8b3928debb71216f5fdc7fced please

karel-m commented 6 years ago

@Tux could you try http://cpan.metacpan.org/authors/id/M/MI/MIK/CryptX-0.060_003.tar.gz ?

Tux commented 6 years ago
All tests successful.
Files=134, Tests=29516, 123 wallclock secs ( 5.75 usr  1.09 sys + 114.27 cusr  6.58 csys = 127.69 CPU)
Result: PASS
karel-m commented 6 years ago

Thanks, CryptX-0.061 released

Tux commented 6 years ago

Just to verify: both my HP-UX 11.11 and 11.31 boxes passed without problems. Thank you for keeping it alive!