| © 2008 W.Ehrhardt |
June 27, 2008 |
Important note for FPC users
During the testing of my Camellia implementation with FPC 2.2.2 RC1 I stumbled
upon a FPC feature (no bug because it is described in the docs) related
to range and overflow checking: Contrary to Turbo Pascal and Delphi the
inc and dec standard procedures perform range checking even with {$Q-}.
A quote from FPC's rtl.pdf for inc:
"If range checking is on, then a range check can occur, or an overflow
error, when an attempt is made to increase X over its maximum value."
But this checking is very inconsistent for the different ordinal types:
during experiments with {$Q-,R+} int64, uint64, longint do not show errors,
but longword, word, byte generate RTE 201.
My std.inc file always sets {$Q-} with the comment:
Most Crypto and CRC/Hash units need Q-, define Q+ locally if needed.
{$R+} is set if the the symbol Debug is defined.
Fortunately for the hash functions longints are not checked.
However, the predefined block cipher TIncProcs increment
bytes and may generate RTE 201 for CTR mode (and EAX) with FPC -dDebug.
The TIncProcs will be replaced during normal updates by (a little
bit slower) range check safe procedures: In the loop bodies
the present code
inc(CTR[j]);
if CTR[j]<>0 then exit;
will be changed to
if CTR[j]=$FF then CTR[j] := 0
else begin
inc(CTR[j]);
exit;
end;
Complete pre-update replacements units are in the archive
ctrunits_2008-06-27.zip.