Changeset 21422 for trunk/src


Ignore:
Timestamp:
Aug 17, 2010, 11:51:11 PM (15 years ago)
Author:
dmik
Message:

Attempted to fix broken rsaenh.dll functionality when built by VAC 3 (that doesn't have a 64-bit integer type).

Location:
trunk/src/rsaenh
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/rsaenh/des.c

    r21363 r21422  
    66 * Based on public domain code by Tom St Denis (tomstdenis@iahu.ca)
    77 * and Dobes Vandermeer.
    8  * 
     8 *
    99 * This library is free software; you can redistribute it and/or
    1010 * modify it under the terms of the GNU Lesser General Public
     
    2323
    2424/*
    25  * This file contains code from the LibTomCrypt cryptographic 
     25 * This file contains code from the LibTomCrypt cryptographic
    2626 * library written by Tom St Denis (tomstdenis@iahu.ca). LibTomCrypt
    2727 * is in the public domain. The code in this file is tailored to
    2828 * special requirements. Take a look at http://libtomcrypt.org for the
    29  * original version. 
     29 * original version.
    3030 */
    3131
    3232#include "tomcrypt.h"
    3333
    34 #define EN0 0 
     34#define EN0 0
    3535#define DE1 1
    3636
    3737static const ulong32 bytebit[8] =
    3838{
    39     0200, 0100, 040, 020, 010, 04, 02, 01 
     39    0200, 0100, 040, 020, 010, 04, 02, 01
    4040};
    4141
     
    4747    0x800UL,     0x400UL,     0x200UL,     0x100UL,
    4848    0x80UL,      0x40UL,      0x20UL,      0x10UL,
    49     0x8UL,       0x4UL,       0x2UL,       0x1L 
     49    0x8UL,       0x4UL,       0x2UL,       0x1L
    5050};
    5151
     
    5353
    5454static const unsigned char pc1[56] = {
    55     56, 48, 40, 32, 24, 16,  8,  0, 57, 49, 41, 33, 25, 17, 
    56      9,  1, 58, 50, 42, 34, 26, 18, 10,  2, 59, 51, 43, 35, 
     55    56, 48, 40, 32, 24, 16,  8,  0, 57, 49, 41, 33, 25, 17,
     56     9,  1, 58, 50, 42, 34, 26, 18, 10,  2, 59, 51, 43, 35,
    5757    62, 54, 46, 38, 30, 22, 14,  6, 61, 53, 45, 37, 29, 21,
    58     13,  5, 60, 52, 44, 36, 28, 20, 12,  4, 27, 19, 11,  3 
     58    13,  5, 60, 52, 44, 36, 28, 20, 12,  4, 27, 19, 11,  3
    5959};
    6060
    6161static const unsigned char totrot[16] = {
    6262    1,   2,  4,  6,
    63     8,  10, 12, 14, 
    64     15, 17, 19, 21, 
     63    8,  10, 12, 14,
     64    15, 17, 19, 21,
    6565    23, 25, 27, 28
    6666};
     
    12791279  CONST64(0x40404000,0x00404040), CONST64(0x40404010,0x00404040), CONST64(0x40404000,0x40404040), CONST64(0x40404010,0x40404040)
    12801280  }};
    1281  
     1281
    12821282
    12831283static void cookey(const ulong32 *raw1, ulong32 *keyout);
     
    13641364    right = block[1];
    13651365
    1366     tmp = des_ip[0][byte(leftt, 0)] ^
    1367           des_ip[1][byte(leftt, 1)] ^
    1368           des_ip[2][byte(leftt, 2)] ^
    1369           des_ip[3][byte(leftt, 3)] ^
    1370           des_ip[4][byte(right, 0)] ^
    1371           des_ip[5][byte(right, 1)] ^
    1372           des_ip[6][byte(right, 2)] ^
    1373           des_ip[7][byte(right, 3)];
    1374     leftt = (ulong32)(tmp >> 32);
    1375     right = (ulong32)(tmp & 0xFFFFFFFFUL);
     1366    tmp =          des_ip[0][byte(leftt, 0)];
     1367    XOR_int64(tmp, des_ip[1][byte(leftt, 1)]);
     1368    XOR_int64(tmp, des_ip[2][byte(leftt, 2)]);
     1369    XOR_int64(tmp, des_ip[3][byte(leftt, 3)]);
     1370    XOR_int64(tmp, des_ip[4][byte(right, 0)]);
     1371    XOR_int64(tmp, des_ip[5][byte(right, 1)]);
     1372    XOR_int64(tmp, des_ip[6][byte(right, 2)]);
     1373    XOR_int64(tmp, des_ip[7][byte(right, 3)]);
     1374    leftt = (ulong32)(HI_int64(tmp));
     1375    right = (ulong32)(LO_int64(tmp));
    13761376
    13771377    for (cur_round = 0; cur_round < 8; cur_round++) {
     
    13991399    }
    14001400
    1401     tmp = des_fp[0][byte(leftt, 0)] ^
    1402           des_fp[1][byte(leftt, 1)] ^
    1403           des_fp[2][byte(leftt, 2)] ^
    1404           des_fp[3][byte(leftt, 3)] ^
    1405           des_fp[4][byte(right, 0)] ^
    1406           des_fp[5][byte(right, 1)] ^
    1407           des_fp[6][byte(right, 2)] ^
    1408           des_fp[7][byte(right, 3)];
    1409     leftt = (ulong32)(tmp >> 32);
    1410     right = (ulong32)(tmp & 0xFFFFFFFFUL);
    1411    
     1401    tmp =          des_ip[0][byte(leftt, 0)];
     1402    XOR_int64(tmp, des_ip[1][byte(leftt, 1)]);
     1403    XOR_int64(tmp, des_ip[2][byte(leftt, 2)]);
     1404    XOR_int64(tmp, des_ip[3][byte(leftt, 3)]);
     1405    XOR_int64(tmp, des_ip[4][byte(right, 0)]);
     1406    XOR_int64(tmp, des_ip[5][byte(right, 1)]);
     1407    XOR_int64(tmp, des_ip[6][byte(right, 2)]);
     1408    XOR_int64(tmp, des_ip[7][byte(right, 3)]);
     1409    leftt = (ulong32)(HI_int64(tmp));
     1410    right = (ulong32)(LO_int64(tmp));
     1411
    14121412    block[0] = right;
    14131413    block[1] = leftt;
  • trunk/src/rsaenh/tomcrypt.h

    r21363 r21422  
    2323
    2424/*
    25  * This file contains code from the LibTomCrypt cryptographic 
     25 * This file contains code from the LibTomCrypt cryptographic
    2626 * library written by Tom St Denis (tomstdenis@iahu.ca). LibTomCrypt
    2727 * is in the public domain. The code in this file is tailored to
    2828 * special requirements. Take a look at http://libtomcrypt.org for the
    29  * original version. 
     29 * original version.
    3030 */
    3131
     
    3737#include <stdlib.h>
    3838#include <limits.h>
     39
     40#if defined(__WIN32OS2__) && (__IBMC__ < 400) && (__IBMCPP__ < 360) && !defined(__WATCOMC__) && !defined(__EMX__)
     41
     42/* provide a better 64-bit integer storage than double */
     43typedef struct
     44{
     45    int lo;
     46    int hi;
     47} __long_long;
     48#define __int64 __long_long
     49
     50#define XOR_int64(a, b)     ((a).hi ^= (b).hi, (a).lo ^= (b).lo)
     51#define HI_int64(a)         ((a).hi)
     52#define LO_int64(a)         ((a).lo)
     53#define ASSIGN_int64(a, b)  ((a).hi = 0, (a).lo = (int)(b))
     54
     55#else
     56
     57#define XOR_int64(a, b)     ((a) ^= (b))
     58#define HI_int64(a)         ((a) >> 32)
     59#define LO_int64(a)         ((a) & 0xFFFFFFFFUL)
     60#define ASSIGN_int64(a, b)  ((a) = (b))
     61
     62#endif
     63
    3964#include "basetsd.h"
    4065
     
    76101};
    77102
     103#if defined(__WIN32OS2__) && (__IBMC__ < 400) && (__IBMCPP__ < 360) && !defined(__WATCOMC__) && !defined(__EMX__)
     104#define CONST64(a,b) { (b), (a) }
     105#else
    78106#define CONST64(a,b) ((((ULONG64)(a)) << 32) | (b))
     107#endif
    79108typedef ULONG64 ulong64;
    80109
    81 /* this is the "32-bit at least" data type 
    82  * Re-define it to suit your platform but it must be at least 32-bits 
     110/* this is the "32-bit at least" data type
     111 * Re-define it to suit your platform but it must be at least 32-bits
    83112 */
    84113typedef ULONG32 ulong32;
     
    118147#define byte(x, n) (((x) >> (8 * (n))) & 255)
    119148
    120 typedef struct tag_rc2_key { 
    121         unsigned xkey[64]; 
     149typedef struct tag_rc2_key {
     150        unsigned xkey[64];
    122151} rc2_key;
    123152
     
    182211 * [any size beyond that is ok provided it doesn't overflow the data type]
    183212 */
     213#if defined(__WIN32OS2__) && (__IBMC__ < 400) && (__IBMCPP__ < 360) && !defined(__WATCOMC__) && !defined(__EMX__)
     214typedef unsigned short     mp_digit;
     215typedef unsigned long      mp_word;
     216#define DIGIT_BIT 14
     217#else
    184218typedef unsigned long      mp_digit;
    185219typedef ulong64            mp_word;
    186220#define DIGIT_BIT 28
    187    
     221#endif
     222
    188223#define MP_DIGIT_BIT     DIGIT_BIT
    189224#define MP_MASK          ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
     
    217252/* #define MP_LOW_MEM */
    218253
     254#if defined(__WIN32OS2__) && (__IBMC__ < 400) && (__IBMCPP__ < 360) && !defined(__WATCOMC__) && !defined(__EMX__)
     255#define MP_PREC                 128    /* default digits of precision */
     256#else
    219257#define MP_PREC                 64     /* default digits of precision */
     258#endif
    220259
    221260/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
     
    497536
    498537/* This gives [for a given bit size] the number of trials required
    499  * such that Miller-Rabin gives a prob of failure lower than 2^-96 
     538 * such that Miller-Rabin gives a prob of failure lower than 2^-96
    500539 */
    501540int mp_prime_rabin_miller_trials(int size);
     
    518557
    519558/* makes a truly random prime of a given size (bytes),
    520  * call with bbs = 1 if you want it to be congruent to 3 mod 4 
     559 * call with bbs = 1 if you want it to be congruent to 3 mod 4
    521560 *
    522561 * You have to supply a callback which fills in a buffer with random bytes.  "dat" is a parameter you can
     
    531570 *
    532571 * Flags are as follows:
    533  * 
     572 *
    534573 *   LTM_PRIME_BBS      - make prime congruent to 3 mod 4
    535574 *   LTM_PRIME_SAFE     - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
Note: See TracChangeset for help on using the changeset viewer.