Avoid signed left shift overflows in curve25519-donna: manual preparation

Setup types and SHL32/64 macros for unsigned bitwise operations in
donna. Refactor generic OVERFLOW_SAFE_SIGNED_LSHIFT into
torint.h (it's now used by ed25519 and curve25519-donna).

Affects generic curve25519-donna.c only - c64 is not affected.
Avoid signed left shift overflows in curve25519-donna: automated conversion

Convert all << and <<= to SHL32/64 macros for safe unsigned bitwise
operations in generic curve25519-donna.c (c64 is not affected)
using the perl script below, a simplified version of
scripts/maint/safe_shl.pl

Behaviour and assembly code shouldn't change, as this patch makes explicit
the existing assumption that bits that are shifted out the left are ignored.

Fixes bug 13538.

#!/usr/bin/perl -p -w -i

BEGIN { %vartypes = (); }

if (/^[{}]/) {
    %vartypes = ();
}

# Discover the type of each variable
if (/(?:(?:^ *)|(?:\())(?:const +)?s(\d+) +([a-zA-Z_][_a-zA-Z0-9]*)(\[\d+\])?/) {
    # capture s\d\d declared in function arguments, and/or as arrays
    if (defined $3) {
        $vartypes{"*".$2} = $1;
    } else {
        $vartypes{$2} = $1;
    }
} elsif (/(?:(?:^ *)|(?:\())limb +((?:\*)?[a-zA-Z_][_a-zA-Z0-9]*)/) {
    # capture limb declared in function arguments, and/or as pointers
    $vartypes{$1} = '64';
}

# This fixes at most one shift per line. But that's all the code does.
if (/([a-zA-Z_][a-zA-Z_0-9]*)(?:\[\d+\])? *<< *(\d+)/) {
    $v = $1;
    if (exists $vartypes{$v}) {
        # replace a << n
        s/$v *<< *(\d+)/SHL$vartypes{$v}($v,$1)/;
    } elsif (exists $vartypes{"*".$v}) {
        # replace a[i] << n
        s/$v(\[\d+\]) *<< *(\d+)/SHL$vartypes{"*".$v}($v$1,$2)/;
    }
} elsif (/([a-zA-Z_][a-zA-Z_0-9]*)(?:\[\d+\])? *<<= *(\d+)/) {
    $v = $1;
    if (exists $vartypes{$v}) {
        # replace a <<= n
        s/$v *<<= *(\d+)/$v = SHL$vartypes{$v}($v,$1)/;
    } elsif (exists $vartypes{"*".$v}) {
        # replace a[i] <<= n
        s/$v(\[\d+\]) *<<= *(\d+)/$v$1 = SHL$vartypes{"*".$v}($v$1,$2)/;
    }
}

# Remove extra parenthesis
s/\(SHL64\((.*)\)\)/SHL64\($1\)/;
s/\(SHL32\((.*)\)\)/SHL32\($1\)/;
Document the safe_shl.pl code transformation in the README
Merge branch 'bug13538-donna-signed-shift' into bug13718-bug14001-fast-bootstrap-no-warning
Merge curve25519_donna 32-bit changes
Fix mistaken merge
Fix space issues in dirserv.c