Unnamed Fossil Project

Check-in [f79a51d5e8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:updated
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:f79a51d5e839d48a35d773a80ca6512fc1fd7dc4
User & Date: alexey@sudachen.name 2011-08-05 14:13:17
Context
2011-08-07
17:41
updated check-in: cf0c3331be user: alexey@sudachen.name tags: trunk
2011-08-05
14:13
updated check-in: f79a51d5e8 user: alexey@sudachen.name tags: trunk
2011-07-30
08:02
updated check-in: 784a3c2080 user: alexey@sudachen.name tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to aes.hc.

1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
....
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
....
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
#endif
  ;

void *Aes_Encipher(char *S)
#ifdef _YOYO_AES_BUILTIN
  {
    byte_t key[32];
    Sha2_Sign_Sign_Data(S,strlen(S),key);
    return Aes_Init_Encipher(key,256);
  }
#endif
  ;


void *Aes_Init_Decipher(void *key,int key_len) 
................................................................................
#endif
  ;

void *Aes_Decipher(char *S)
#ifdef _YOYO_AES_BUILTIN
  {
    byte_t key[32];
    Sha2_Sign_Sign_Data(S,strlen(S),key);
    return Aes_Init_Decipher(key,256);
  }
#endif
  ;
  
void Aes_Encrypt(char *data, int len, char *S)
#ifdef _YOYO_AES_BUILTIN
  {
    int i;
    YOYO_AES actx = {0,0,{0}};
    byte_t key[32];
    Sha2_Sign_Sign_Data(S,strlen(S),key);
    Aes_Init_Encipher_Static(&actx,key,256);
    
    for ( i = 0; i < len && len-i >= 16 ; i += 16 )
      {
        Aes_Encrypt16(&actx,data+i);
      }
  }
................................................................................

void Aes_Decrypt(char *data, int len, char *S)
#ifdef _YOYO_AES_BUILTIN
  {
    int i;
    YOYO_AES actx = {0,0,{0}};
    byte_t key[32];
    Sha2_Sign_Sign_Data(S,strlen(S),key);
    Aes_Init_Decipher_Static(&actx,key,256);
    
    for ( i = 0; i < len && len-i >= 16 ; i += 16 )
      {
        Aes_Decrypt16(&actx,data+i);
      }
  }
#endif
  ;

#endif /* C_once_88F44E4C_C507_47B8_A162_CBEC13D572DA */









|







 







|











|







 







|













1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
....
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
....
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
#endif
  ;

void *Aes_Encipher(char *S)
#ifdef _YOYO_AES_BUILTIN
  {
    byte_t key[32];
    Sha2_Digest_Digest(S,strlen(S),key);
    return Aes_Init_Encipher(key,256);
  }
#endif
  ;


void *Aes_Init_Decipher(void *key,int key_len) 
................................................................................
#endif
  ;

void *Aes_Decipher(char *S)
#ifdef _YOYO_AES_BUILTIN
  {
    byte_t key[32];
    Sha2_Digest_Digest(S,strlen(S),key);
    return Aes_Init_Decipher(key,256);
  }
#endif
  ;
  
void Aes_Encrypt(char *data, int len, char *S)
#ifdef _YOYO_AES_BUILTIN
  {
    int i;
    YOYO_AES actx = {0,0,{0}};
    byte_t key[32];
    Sha2_Digest_Digest(S,strlen(S),key);
    Aes_Init_Encipher_Static(&actx,key,256);
    
    for ( i = 0; i < len && len-i >= 16 ; i += 16 )
      {
        Aes_Encrypt16(&actx,data+i);
      }
  }
................................................................................

void Aes_Decrypt(char *data, int len, char *S)
#ifdef _YOYO_AES_BUILTIN
  {
    int i;
    YOYO_AES actx = {0,0,{0}};
    byte_t key[32];
    Sha2_Digest_Digest(S,strlen(S),key);
    Aes_Init_Decipher_Static(&actx,key,256);
    
    for ( i = 0; i < len && len-i >= 16 ; i += 16 )
      {
        Aes_Decrypt16(&actx,data+i);
      }
  }
#endif
  ;

#endif /* C_once_88F44E4C_C507_47B8_A162_CBEC13D572DA */


Changes to bigint.hc.

1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
....
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
....
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
    YOYO_PRIME_TEST_Q = 32,
  };
#endif

halflong_t First_Prime(int no)
#ifdef _YOYO_BINGINT_BUILTIN
  {
    STRICT_REQUIRE(no >= 0 && no<YOY_PRIME_MAX_COUNT);
    return First_Prime_Values[no];
  }
#endif
  ;

int Bigint_Ferma_Prime_Test(YOYO_BIGINT *bint, int q)
#ifdef _YOYO_BINGINT_BUILTIN
................................................................................
      {
        int i;
        YOYO_BIGINT *p   = Bigint_Alloca(bint->digits);
        YOYO_BIGINT *p_1 = Bigint_Alloca(bint->digits);
        YOYO_BIGINT *t   = Bigint_Alloca(1);
    
        if ( !q ) q = YOYO_PRIME_TEST_Q;
        STRICT_REQUIRE( q > 0 && q < PRIME_MAX_COUNT );

        p = Bigint_Copy_To(bint,p);
        p_1 = Bigint_Sub_Short(Bigint_Copy_To(bint,p_1),1);

        for ( i =0; is_prime && i < q; ++i )
          {
            t->value[0] = First_Prime_Values[i];
................................................................................
    int i,n;
    YOYO_BIGINT *ret = 0;
    YOYO_BIGINT *r = tmp;
    
    if ( !q ) q = YOYO_PRIME_TEST_Q;
    if ( !maxcount ) maxcount = 101;
    
    STRICT_REQUIRE( maxount > 0 );
    STRICT_REQUIRE( bits > 8 );
    STRICT_REQUIRE( q > 0 && q < 500 );

    n = Yo_MIN(128,bits-3);
    if ( !r )
      r = Bigint_Alloca(Bigint_Digits_Of_Bits(bits)+1);
    







|







 







|







 







|







1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
....
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
....
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
    YOYO_PRIME_TEST_Q = 32,
  };
#endif

halflong_t First_Prime(int no)
#ifdef _YOYO_BINGINT_BUILTIN
  {
    STRICT_REQUIRE(no >= 0 && no < YOYO_PRIME_MAX_COUNT);
    return First_Prime_Values[no];
  }
#endif
  ;

int Bigint_Ferma_Prime_Test(YOYO_BIGINT *bint, int q)
#ifdef _YOYO_BINGINT_BUILTIN
................................................................................
      {
        int i;
        YOYO_BIGINT *p   = Bigint_Alloca(bint->digits);
        YOYO_BIGINT *p_1 = Bigint_Alloca(bint->digits);
        YOYO_BIGINT *t   = Bigint_Alloca(1);
    
        if ( !q ) q = YOYO_PRIME_TEST_Q;
        STRICT_REQUIRE( q > 0 && q < YOYO_PRIME_MAX_COUNT );

        p = Bigint_Copy_To(bint,p);
        p_1 = Bigint_Sub_Short(Bigint_Copy_To(bint,p_1),1);

        for ( i =0; is_prime && i < q; ++i )
          {
            t->value[0] = First_Prime_Values[i];
................................................................................
    int i,n;
    YOYO_BIGINT *ret = 0;
    YOYO_BIGINT *r = tmp;
    
    if ( !q ) q = YOYO_PRIME_TEST_Q;
    if ( !maxcount ) maxcount = 101;
    
    STRICT_REQUIRE( maxcount > 0 );
    STRICT_REQUIRE( bits > 8 );
    STRICT_REQUIRE( q > 0 && q < 500 );

    n = Yo_MIN(128,bits-3);
    if ( !r )
      r = Bigint_Alloca(Bigint_Digits_Of_Bits(bits)+1);
    

Changes to blowfish.hc.

473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
#endif
  ;

void *Blowfish_Object_Init_With_Text_Key(char *Skey)
#ifdef _YOYO_BLOWFISH_BUILTIN
  {
    byte_t key[16] = {0};
    Md5_Sign_Data(Skey,strlen(Skey),key);
    return Blowfish_Init(key,16);
  }
#endif
  ;

#define Blowfish_Decipher(Skey) Blowfish_Object_Init_With_Text_Key(Skey)
#define Blowfish_Encipher(Skey) Blowfish_Object_Init_With_Text_Key(Skey)







|







473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
#endif
  ;

void *Blowfish_Object_Init_With_Text_Key(char *Skey)
#ifdef _YOYO_BLOWFISH_BUILTIN
  {
    byte_t key[16] = {0};
    Md5_Digest(Skey,strlen(Skey),key);
    return Blowfish_Init(key,16);
  }
#endif
  ;

#define Blowfish_Decipher(Skey) Blowfish_Object_Init_With_Text_Key(Skey)
#define Blowfish_Encipher(Skey) Blowfish_Object_Init_With_Text_Key(Skey)

Changes to core.hc.

25
26
27
28
29
30
31

32
33
34
35
36
37
38
...
105
106
107
108
109
110
111
112
113

114
115
116
117
118
119
120
...
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165












166
167
168
169
170
171
172
...
394
395
396
397
398
399
400





401
402
403
404
405
406
407
be used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization of the copyright holder.

*/

#ifndef C_once_6973F3BA_26FA_434D_9ED9_FF5389CE421C
#define C_once_6973F3BA_26FA_434D_9ED9_FF5389CE421C


#if defined _MSC_VER && _MSC_VER > 1400
#pragma warning(disable:4996) /*The POSIX name for this item is deprecated*/
# ifndef _CRT_SECURE_NO_WARNINGS
#   define _CRT_SECURE_NO_WARNINGS
# endif
#endif
................................................................................
# else 
#   define malloc_size(Ptr) malloc_usable_size(Ptr)
# endif
#endif

#define iszof(x)     ((int)sizeof(x))
#define iszof_double ((int)sizeof(double))
#define iszof_long   ((int)sizeof(int))
#define iszof_wchar  ((int)sizeof(wchar_t))


typedef unsigned char  byte_t;
typedef unsigned short ushort_t;
typedef unsigned int   uint_t;
typedef unsigned long  ulong_t;

#ifndef __windoze
................................................................................
#else
# define __Yo_FILE__ 0
# define __Yo_Expr__(Expr) 0
# define Yo_Raise(Error,Msg,File,Line) _Yo_Raise(Error,0,0,0)
# define Yo_Fatal(Error,Msg,File,Line) _Yo_Fatal(Error,0,0,0)
#endif

#define Yo_MIN(a,b) ( (a) < (b) ? (a) : (b) )
#define Yo_MAX(a,b) ( (a) > (b) ? (a) : (b) )

#define YOYO_COMPOSE2(a,b) a##b
#define YOYO_COMPOSE3(a,b,c) a##b##_##c
#define YOYO_ID(Name,Line) YOYO_COMPOSE3(_YoYo_Label_,Name,Line)
#define YOYO_LOCAL_ID(Name) YOYO_ID(Name,__LINE__)

#ifdef _YOYO_CORE_BUILTIN
# define _YOYO_CORE_BUILTIN_CODE(Code) Code
# define _YOYO_CORE_EXTERN 
#else
# define _YOYO_CORE_BUILTIN_CODE(Code)
# define _YOYO_CORE_EXTERN extern 
#endif













_YOYO_CORE_EXTERN char Oj_Destruct_OjMID[] _YOYO_CORE_BUILTIN_CODE ( = "~/@" );
_YOYO_CORE_EXTERN char Oj_Destruct_Element_OjMID[] _YOYO_CORE_BUILTIN_CODE ( = "~1/@" );
_YOYO_CORE_EXTERN char Oj_Compare_Elements_OjMID[] _YOYO_CORE_BUILTIN_CODE ( = "?2/**" );
_YOYO_CORE_EXTERN char Oj_Compare_Keys_OjMID[] _YOYO_CORE_BUILTIN_CODE ( = "?3/**" );
_YOYO_CORE_EXTERN char Oj_Clone_OjMID[] _YOYO_CORE_BUILTIN_CODE ( = "$=/@" );
_YOYO_CORE_EXTERN char Oj_Count_OjMID[] _YOYO_CORE_BUILTIN_CODE ( = "$#/@" );
_YOYO_CORE_EXTERN char Oj_Set_Key_OjMID[] _YOYO_CORE_BUILTIN_CODE ( = ">+S>/@*" );
................................................................................
  {
    if ( a ) --a; 
    return 1<<Bitcount_Of(a);
  }
#endif
  ;






uint_t Align_To_Pow2(uint_t a, uint_t mod)
#ifdef _YOYO_CORE_BUILTIN
  {
    uint_t Q;
    if ( !mod ) mod = 1;
    Q = Min_Pow2(mod) - 1;
    return (a+Q)&~Q;







>







 







|

>







 







<
<
<













>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
...
145
146
147
148
149
150
151



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
...
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
be used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization of the copyright holder.

*/

#ifndef C_once_6973F3BA_26FA_434D_9ED9_FF5389CE421C
#define C_once_6973F3BA_26FA_434D_9ED9_FF5389CE421C
#define YOYO_CORE_VERSION 1000

#if defined _MSC_VER && _MSC_VER > 1400
#pragma warning(disable:4996) /*The POSIX name for this item is deprecated*/
# ifndef _CRT_SECURE_NO_WARNINGS
#   define _CRT_SECURE_NO_WARNINGS
# endif
#endif
................................................................................
# else 
#   define malloc_size(Ptr) malloc_usable_size(Ptr)
# endif
#endif

#define iszof(x)     ((int)sizeof(x))
#define iszof_double ((int)sizeof(double))
#define iszof_long   ((int)sizeof(long))
#define iszof_wchar  ((int)sizeof(wchar_t))
#define __Offset_Of(T,Memb) ((longptr_t)(&((T*)0)->Memb))

typedef unsigned char  byte_t;
typedef unsigned short ushort_t;
typedef unsigned int   uint_t;
typedef unsigned long  ulong_t;

#ifndef __windoze
................................................................................
#else
# define __Yo_FILE__ 0
# define __Yo_Expr__(Expr) 0
# define Yo_Raise(Error,Msg,File,Line) _Yo_Raise(Error,0,0,0)
# define Yo_Fatal(Error,Msg,File,Line) _Yo_Fatal(Error,0,0,0)
#endif




#define YOYO_COMPOSE2(a,b) a##b
#define YOYO_COMPOSE3(a,b,c) a##b##_##c
#define YOYO_ID(Name,Line) YOYO_COMPOSE3(_YoYo_Label_,Name,Line)
#define YOYO_LOCAL_ID(Name) YOYO_ID(Name,__LINE__)

#ifdef _YOYO_CORE_BUILTIN
# define _YOYO_CORE_BUILTIN_CODE(Code) Code
# define _YOYO_CORE_EXTERN 
#else
# define _YOYO_CORE_BUILTIN_CODE(Code)
# define _YOYO_CORE_EXTERN extern 
#endif

#define Yo_MIN(a,b) ( (a) < (b) ? (a) : (b) )
#define Yo_MAX(a,b) ( (a) > (b) ? (a) : (b) )
#define Yo_ALIGNU(a,n) ( ((a) + ((n) - 1))&~((n) - 1) )

#define YOYO_REPN_2(Val)   Val,Val
#define YOYO_REPN_4(Val)   YOYO_REPN_2(Val),YOYO_REPN_2(Val)
#define YOYO_REPN_8(Val)   YOYO_REPN_4(Val),YOYO_REPN_4(Val)
#define YOYO_REPN_16(Val)  YOYO_REPN_8(Val),YOYO_REPN_8(Val)
#define YOYO_REPN_32(Val)  YOYO_REPN_16(Val),YOYO_REPN_16(Val)
#define YOYO_REPN_64(Val)  YOYO_REPN_32(Val),YOYO_REPN_32(Val)
#define YOYO_REPN_128(Val) YOYO_REPN_64(Val),YOYO_REPN_64(Val)

_YOYO_CORE_EXTERN char Oj_Destruct_OjMID[] _YOYO_CORE_BUILTIN_CODE ( = "~/@" );
_YOYO_CORE_EXTERN char Oj_Destruct_Element_OjMID[] _YOYO_CORE_BUILTIN_CODE ( = "~1/@" );
_YOYO_CORE_EXTERN char Oj_Compare_Elements_OjMID[] _YOYO_CORE_BUILTIN_CODE ( = "?2/**" );
_YOYO_CORE_EXTERN char Oj_Compare_Keys_OjMID[] _YOYO_CORE_BUILTIN_CODE ( = "?3/**" );
_YOYO_CORE_EXTERN char Oj_Clone_OjMID[] _YOYO_CORE_BUILTIN_CODE ( = "$=/@" );
_YOYO_CORE_EXTERN char Oj_Count_OjMID[] _YOYO_CORE_BUILTIN_CODE ( = "$#/@" );
_YOYO_CORE_EXTERN char Oj_Set_Key_OjMID[] _YOYO_CORE_BUILTIN_CODE ( = ">+S>/@*" );
................................................................................
  {
    if ( a ) --a; 
    return 1<<Bitcount_Of(a);
  }
#endif
  ;

int Yo_Mini(int a, int b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MIN(a,b); });
int Yo_Maxi(int a, int b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MAX(a,b); });
uint_t Yo_Minu(uint_t a, uint_t b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MIN(a,b); });
uint_t Yo_Maxu(uint_t a, uint_t b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MAX(a,b); });

uint_t Align_To_Pow2(uint_t a, uint_t mod)
#ifdef _YOYO_CORE_BUILTIN
  {
    uint_t Q;
    if ( !mod ) mod = 1;
    Q = Min_Pow2(mod) - 1;
    return (a+Q)&~Q;

Changes to datetime.hc.

98
99
100
101
102
103
104













105
106
#define Dt_Min(Dt)  ((int)((Dt)>>16)&0x0ff)
#define Dt_Sec(Dt)  ((int)((Dt)>> 8)&0x0ff)
#define Dt_Msec(Dt) ((int)((Dt)>> 0)&0x0ff)
#define Dt_Year(Dt) ((int)((Dt)>>(32+16))&0x0ffff)
#define Dt_Mon(Dt)  ((int)((Dt)>>(32+ 8))&0x0ff)
#define Dt_Mday(Dt) ((int)((Dt)>>(32+ 0))&0x0ff)














#endif /* C_once_A998DD5F_3579_4977_B115_DCCE42423C49 */








>
>
>
>
>
>
>
>
>
>
>
>
>


98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#define Dt_Min(Dt)  ((int)((Dt)>>16)&0x0ff)
#define Dt_Sec(Dt)  ((int)((Dt)>> 8)&0x0ff)
#define Dt_Msec(Dt) ((int)((Dt)>> 0)&0x0ff)
#define Dt_Year(Dt) ((int)((Dt)>>(32+16))&0x0ffff)
#define Dt_Mon(Dt)  ((int)((Dt)>>(32+ 8))&0x0ff)
#define Dt_Mday(Dt) ((int)((Dt)>>(32+ 0))&0x0ff)

#ifdef __windoze
  void Timet_To_Filetime(time_t t, FILETIME *pft)
# ifdef _YOYO_DATETIME_BUILTIN
    {
      LONGLONG ll;
      ll = Int32x32To64(t, 10000000) + 116444736000000000;
      pft->dwLowDateTime = (DWORD)ll;
      pft->dwHighDateTime = ll >> 32;
    }
# endif
    ;
#endif /*__windoze*/

#endif /* C_once_A998DD5F_3579_4977_B115_DCCE42423C49 */

Changes to file.hc.

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
....
1009
1010
1011
1012
1013
1014
1015

1016
1017
1018
1019
1020
1021
1022
....
1199
1200
1201
1202
1203
1204
1205
1206
1207






1208
1209
1210
1211
1212
1213
1214
....
1239
1240
1241
1242
1243
1244
1245

1246
1247
1248
1249
1250
1251
1252
# define _YOYO_FILE_BUILTIN_CODE(Code)
# define _YOYO_FILE_EXTERN extern
#endif

char *Path_Basename(char *path)
#ifdef _YOYO_FILE_BUILTIN
  {
    char *ret = 0;
    char *p = strrchr(path,'/');
  #ifdef __windoze
    char *p2 = strrchr(path,'\\');
    if ( !p || p < p2 ) p = p2;
  #endif
    if ( p )
      ret = Str_Copy(p+1,-1);
................................................................................
    
    for ( ; *nonst; ++nonst )
      switch ( *nonst )
        {
          case '+': ac_plus = 1; break;
          case 'r': ac_r = 1; break;
          case 'w': ac_w = 1; break;

          case 'a': ac_a = 1; break;
          case 't': ac_t = 1; break;
          case 'b': ac_b = 1; break;
          case 'n': ac_w = ac_plus = 1; break;
        }
        
    if ( ac_w ) *ac++ = 'w';
................................................................................
#ifdef _YOYO_FILE_BUILTIN
  {
    int i;
    
    for ( i = 0; i < count;  )
      {
        int r = read(fd,(char*)data+i,count-i);
        if ( r >= 0 )
          i += r;






        else if ( errno != EAGAIN )
          {
            int err = errno;
            if ( do_raise )
              __Raise_Format(YOYO_ERROR_IO,(__yoTa("failed to read file: %s",0),strerror(err)));
            return err;
          }
................................................................................
#define Open_File(Name,Opt) Fd_Open_File(Name,Opt,0600,0)
#define Open_File_Raise(Name,Opt) Fd_Open_File(Name,Opt,0600,1)
int Fd_Open_File(char *name, int opt, int secu, int do_raise)
#ifdef _YOYO_FILE_BUILTIN
  {
    int fd;
    #ifdef __windoze

      fd = _wopen(Str_Utf8_To_Unicode(name),opt,secu);
    #else
      fd = open(name,opt,secu);
    #endif
    if ( fd < 0 )
      {
        int err = errno;







|







 







>







 







|

>
>
>
>
>
>







 







>







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
....
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
....
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
....
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
# define _YOYO_FILE_BUILTIN_CODE(Code)
# define _YOYO_FILE_EXTERN extern
#endif

char *Path_Basename(char *path)
#ifdef _YOYO_FILE_BUILTIN
  {
    char *ret = path;
    char *p = strrchr(path,'/');
  #ifdef __windoze
    char *p2 = strrchr(path,'\\');
    if ( !p || p < p2 ) p = p2;
  #endif
    if ( p )
      ret = Str_Copy(p+1,-1);
................................................................................
    
    for ( ; *nonst; ++nonst )
      switch ( *nonst )
        {
          case '+': ac_plus = 1; break;
          case 'r': ac_r = 1; break;
          case 'w': ac_w = 1; break;
          case 'c': ac_w = ac_plus = 1; break;
          case 'a': ac_a = 1; break;
          case 't': ac_t = 1; break;
          case 'b': ac_b = 1; break;
          case 'n': ac_w = ac_plus = 1; break;
        }
        
    if ( ac_w ) *ac++ = 'w';
................................................................................
#ifdef _YOYO_FILE_BUILTIN
  {
    int i;
    
    for ( i = 0; i < count;  )
      {
        int r = read(fd,(char*)data+i,count-i);
        if ( r > 0 )
          i += r;
        else if ( !r )
          {
            if ( do_raise )
              __Raise_Format(YOYO_ERROR_IO,(__yoTa("failed to read file: %s",0),"eof"));
            return -1;
          }
        else if ( errno != EAGAIN )
          {
            int err = errno;
            if ( do_raise )
              __Raise_Format(YOYO_ERROR_IO,(__yoTa("failed to read file: %s",0),strerror(err)));
            return err;
          }
................................................................................
#define Open_File(Name,Opt) Fd_Open_File(Name,Opt,0600,0)
#define Open_File_Raise(Name,Opt) Fd_Open_File(Name,Opt,0600,1)
int Fd_Open_File(char *name, int opt, int secu, int do_raise)
#ifdef _YOYO_FILE_BUILTIN
  {
    int fd;
    #ifdef __windoze
      if ( !(opt & _O_TEXT) ) opt |= _O_BINARY;
      fd = _wopen(Str_Utf8_To_Unicode(name),opt,secu);
    #else
      fd = open(name,opt,secu);
    #endif
    if ( fd < 0 )
      {
        int err = errno;

Changes to md5.hc.

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54


55
56
57
58













59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
...
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
...
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
...
308
309
310
311
312
313
314
315





























































































316
317
*/

#ifndef C_once_C5021104_5DB9_4FCC_BAFC_AFB22BD458D3
#define C_once_C5021104_5DB9_4FCC_BAFC_AFB22BD458D3

#include "core.hc"

typedef struct _YOYO_MD5_SIGNER
  {
    uint_t state[4];   /* state (ABCD) */
    uint_t count[2];   /* number of bits, modulo 2^64 (lsb first) */
    int    finished;
    byte_t buffer[64]; /* input buffer */
  } YOYO_MD5_SIGNER;



void *Md5_Clone(YOYO_MD5_SIGNER *md5)
#ifdef _YOYO_MD5_BUILTIN
  {
    return Yo_Object_Clone(sizeof(YOYO_MD5_SIGNER),md5);













  }
#endif
  ;
  
void *Md5_Init()
#ifdef _YOYO_MD5_BUILTIN
  {
    static YOYO_FUNCTABLE funcs[] = 
      { {0},
        {Oj_Clone_OjMID, Md5_Clone },
        {0}};
    
    YOYO_MD5_SIGNER *md5 = Yo_Object(sizeof(YOYO_MD5_SIGNER),funcs);

    md5->state[0] = 0x67452301; 
    md5->state[1] = 0xefcdab89; 
    md5->state[2] = 0x98badcfe; 
    md5->state[3] = 0x10325476;

    return md5;
  }
#endif
  ;

void Md5_Update(YOYO_MD5_SIGNER *md5, void *data, int len);
void *Md5_Finish(YOYO_MD5_SIGNER *md5, void *digest);

#define YOYO_MD5_INITIALIZER {{0x67452301,0xefcdab89,0x98badcfe,0x10325476},{0},0,{0}}

void *Md5_Sign_Data(void *data, int len, void *digest)
#ifdef _YOYO_MD5_BUILTIN
  {
    YOYO_MD5_SIGNER md5 = YOYO_MD5_INITIALIZER;
    Md5_Update(&md5,data,len);
    return Md5_Finish(&md5,digest);
  }
#endif
  ;

void *Md5_Sign_Sign_Data(void *data, int len, void *digest)
#ifdef _YOYO_MD5_BUILTIN
  {
    byte_t tmp[16];
    YOYO_MD5_SIGNER md5 = YOYO_MD5_INITIALIZER;
    Md5_Sign_Data(data,len,tmp);
    Md5_Update(&md5,tmp,16);
    Md5_Update(&md5,data,len);
    return Md5_Finish(&md5,digest);
  }
#endif
  ;

#define Md5_Digest_Of(Data,Len) Md5_Sign_Data(Data,Len,0)

#ifdef _YOYO_MD5_BUILTIN

  #if defined _X86 || defined __i386 || defined __x86_64
    #define Md5_Internal_Encode memcpy
    #define Md5_Internal_Decode memcpy
  #else
................................................................................
  #define H(x, y, z) ((x) ^ (y) ^ (z))
  #define I(x, y, z) ((y) ^ ((x) | ~(z)))
  #define FF(a, b, c, d, x, s, ac) (a) += F((b), (c), (d)) + (x) + (ac); (a) = ROTATE_LEFT((a), (s)) + (b)
  #define GG(a, b, c, d, x, s, ac) (a) += G((b), (c), (d)) + (x) + (ac); (a) = ROTATE_LEFT((a), (s)) + (b)
  #define HH(a, b, c, d, x, s, ac) (a) += H((b), (c), (d)) + (x) + (ac); (a) = ROTATE_LEFT((a), (s)) + (b)
  #define II(a, b, c, d, x, s, ac) (a) += I((b), (c), (d)) + (x) + (ac); (a) = ROTATE_LEFT((a), (s)) + (b)

  void Md5_Internal_Transform(YOYO_MD5_SIGNER *md5, void *block)
    {
      enum _S_constants
        {
          S11 = 7,
          S12 = 12,
          S13 = 17,
          S14 = 22,
................................................................................
  #undef I
  #undef ROTATE_LEFT
  #undef FF
  #undef GG
  #undef HH
  #undef II

  void Md5_Update(YOYO_MD5_SIGNER *md5, void *input, int input_length)
    {
      int i, index, partLen;
      uint_t *count = md5->count;
      index = (uint_t)((count[0] >> 3) & 0x3F);
      if ((count[0] += ((uint_t)input_length << 3)) < ((uint_t)input_length << 3))
        count[1]++;
      count[1] += ((uint_t)input_length >> 29);
................................................................................
          index = 0;
        }
      else
        i = 0;
      memcpy(&md5->buffer[index],&((byte_t*)input)[i],input_length-i);
    }

  void *Md5_Finish(YOYO_MD5_SIGNER *md5, void *digest)
    {
      if ( !md5->finished )
        {
          static byte_t PADDING[64] = {
            0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
................................................................................
        }
      if ( !digest ) digest = __Malloc(16);
      Md5_Internal_Encode(digest, md5->state, 16);
      return digest;
    }

#endif /* _YOYO_MD5_BUILTIN */






























































































#endif /* C_once_C5021104_5DB9_4FCC_BAFC_AFB22BD458D3 */








|





|

>
>
|


|
>
>
>
>
>
>
>
>
>
>
>
>
>



|








|
<
<
<
<
<
<
|




|
|



|


|






|



|
|







|







 







|







 







|







 







|







 








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86






87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
...
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
...
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
...
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
*/

#ifndef C_once_C5021104_5DB9_4FCC_BAFC_AFB22BD458D3
#define C_once_C5021104_5DB9_4FCC_BAFC_AFB22BD458D3

#include "core.hc"

typedef struct _YOYO_MD5
  {
    uint_t state[4];   /* state (ABCD) */
    uint_t count[2];   /* number of bits, modulo 2^64 (lsb first) */
    int    finished;
    byte_t buffer[64]; /* input buffer */
  } YOYO_MD5;

typedef YOYO_MD5 YOYO_MD5_SIGNER;

void *Md5_Clone(YOYO_MD5 *md5)
#ifdef _YOYO_MD5_BUILTIN
  {
    return __Clone(sizeof(YOYO_MD5),md5);
  }
#endif
  ;

void * Md5_Start(YOYO_MD5 *md5)
#ifdef _YOYO_MD5_BUILTIN
  {
    memset(md5,0,sizeof(*md5));
    md5->state[0] = 0x67452301; 
    md5->state[1] = 0xefcdab89; 
    md5->state[2] = 0x98badcfe; 
    md5->state[3] = 0x10325476;
    return md5;
  }
#endif
  ;

void *Md5_Init()
#ifdef _YOYO_MD5_BUILTIN
  {
    static YOYO_FUNCTABLE funcs[] = 
      { {0},
        {Oj_Clone_OjMID, Md5_Clone },
        {0}};
    
    YOYO_MD5 *md5 = __Object(sizeof(YOYO_MD5),funcs);






    return Md5_Start(md5);
  }
#endif
  ;

void Md5_Update(YOYO_MD5 *md5, void *data, int len);
void *Md5_Finish(YOYO_MD5 *md5, void *digest);

#define YOYO_MD5_INITIALIZER {{0x67452301,0xefcdab89,0x98badcfe,0x10325476},{0},0,{0}}

void *Md5_Digest(void *data, int len, void *digest)
#ifdef _YOYO_MD5_BUILTIN
  {
    YOYO_MD5 md5 = YOYO_MD5_INITIALIZER;
    Md5_Update(&md5,data,len);
    return Md5_Finish(&md5,digest);
  }
#endif
  ;

void *Md5_Digest_Digest(void *data, int len, void *digest)
#ifdef _YOYO_MD5_BUILTIN
  {
    byte_t tmp[16];
    YOYO_MD5 md5 = YOYO_MD5_INITIALIZER;
    Md5_Digest(data,len,tmp);
    Md5_Update(&md5,tmp,16);
    Md5_Update(&md5,data,len);
    return Md5_Finish(&md5,digest);
  }
#endif
  ;

#define Md5_Digest_Of(Data,Len) Md5_Digest(Data,Len,0)

#ifdef _YOYO_MD5_BUILTIN

  #if defined _X86 || defined __i386 || defined __x86_64
    #define Md5_Internal_Encode memcpy
    #define Md5_Internal_Decode memcpy
  #else
................................................................................
  #define H(x, y, z) ((x) ^ (y) ^ (z))
  #define I(x, y, z) ((y) ^ ((x) | ~(z)))
  #define FF(a, b, c, d, x, s, ac) (a) += F((b), (c), (d)) + (x) + (ac); (a) = ROTATE_LEFT((a), (s)) + (b)
  #define GG(a, b, c, d, x, s, ac) (a) += G((b), (c), (d)) + (x) + (ac); (a) = ROTATE_LEFT((a), (s)) + (b)
  #define HH(a, b, c, d, x, s, ac) (a) += H((b), (c), (d)) + (x) + (ac); (a) = ROTATE_LEFT((a), (s)) + (b)
  #define II(a, b, c, d, x, s, ac) (a) += I((b), (c), (d)) + (x) + (ac); (a) = ROTATE_LEFT((a), (s)) + (b)

  void Md5_Internal_Transform(YOYO_MD5 *md5, void *block)
    {
      enum _S_constants
        {
          S11 = 7,
          S12 = 12,
          S13 = 17,
          S14 = 22,
................................................................................
  #undef I
  #undef ROTATE_LEFT
  #undef FF
  #undef GG
  #undef HH
  #undef II

  void Md5_Update(YOYO_MD5 *md5, void *input, int input_length)
    {
      int i, index, partLen;
      uint_t *count = md5->count;
      index = (uint_t)((count[0] >> 3) & 0x3F);
      if ((count[0] += ((uint_t)input_length << 3)) < ((uint_t)input_length << 3))
        count[1]++;
      count[1] += ((uint_t)input_length >> 29);
................................................................................
          index = 0;
        }
      else
        i = 0;
      memcpy(&md5->buffer[index],&((byte_t*)input)[i],input_length-i);
    }

  void *Md5_Finish(YOYO_MD5 *md5, void *digest)
    {
      if ( !md5->finished )
        {
          static byte_t PADDING[64] = {
            0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
................................................................................
        }
      if ( !digest ) digest = __Malloc(16);
      Md5_Internal_Encode(digest, md5->state, 16);
      return digest;
    }

#endif /* _YOYO_MD5_BUILTIN */

typedef struct _YOYO_HMAC_MD5
  {
    YOYO_MD5 md5;
    byte_t ipad[64];
    byte_t opad[64];
  } YOYO_HMAC_MD5;

void *Hmac_Md5_Clone(YOYO_HMAC_MD5 *hmac)
#ifdef _YOYO_MD5_BUILTIN
  {
    return __Clone(sizeof(YOYO_HMAC_MD5),hmac);
  }
#endif
  ;

void *Hmac_Md5_Start(YOYO_HMAC_MD5 *hmac, void *key, int key_len)
#ifdef _YOYO_MD5_BUILTIN
  {
    int i;
    byte_t sum[16];
    
    if ( key_len > 64 )
      {
        Md5_Start(&hmac->md5);
        Md5_Update(&hmac->md5,key,key_len);
        Md5_Finish(&hmac->md5,sum);
        key = sum;
        key_len = 16;
      }
    
    memset( hmac->ipad, 0x36, 64 );
    memset( hmac->opad, 0x5C, 64 );
    
    for( i = 0; i < key_len; ++i )
      {
        hmac->ipad[i] = (byte_t)( hmac->ipad[i] ^ ((byte_t*)key)[i] );
        hmac->opad[i] = (byte_t)( hmac->opad[i] ^ ((byte_t*)key)[i] );
      }
    
    Md5_Start(&hmac->md5);
    Md5_Update(&hmac->md5,hmac->ipad,64);
    
    memset(sum,0,sizeof(sum));
    return hmac;
  }
#endif
  ;

void *Hmac_Md5_Init(void *key, int key_len)
#ifdef _YOYO_MD5_BUILTIN
  {
    static YOYO_FUNCTABLE funcs[] = 
      { {0},
        {Oj_Clone_OjMID, Hmac_Md5_Clone },
        {0}};
    
    YOYO_HMAC_MD5 *md5 = __Object(sizeof(YOYO_HMAC_MD5),funcs);
    return Hmac_Md5_Start(md5,key,key_len);
  }
#endif
  ;

void Hmac_Md5_Update(YOYO_HMAC_MD5 *hmac, void *input, int input_length)
#ifdef _YOYO_MD5_BUILTIN
  {
    Md5_Update(&hmac->md5,input,input_length);
  }
#endif
  ;

void *Hmac_Md5_Finish(YOYO_HMAC_MD5 *hmac, void *digest)
#ifdef _YOYO_MD5_BUILTIN
  {
    byte_t tmpb[16];
    Md5_Finish(&hmac->md5,tmpb);
    Md5_Start(&hmac->md5);
    Md5_Update(&hmac->md5,&hmac->opad,64);
    Md5_Update(&hmac->md5,tmpb,16);
    memset(tmpb,0,16);
    return Md5_Finish(&hmac->md5,digest);
  }
#endif
  ;

void Hmac_Md5_Reset(YOYO_HMAC_MD5 *hmac)
#ifdef _YOYO_MD5_BUILTIN
  {
    Md5_Start(&hmac->md5);
    Md5_Update(&hmac->md5,hmac->ipad,64);
  }
#endif
  ;

#endif /* C_once_C5021104_5DB9_4FCC_BAFC_AFB22BD458D3 */

Changes to newdes96.hc.

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#endif
  ;

void *NEWDES96_Object_Init_With_Text_Key(char *Skey)
#ifdef _YOYO_NEWDES96_BUILTIN
  {
    byte_t key[16] = {0};
    Md5_Sign_Data(Skey,strlen(Skey),key);
    return NEWDES96_Init(key+1,15);
  }
#endif
  ;

#define NEWDES96_Decipher(Skey) NEWDES96_Object_Init_With_Text_Key(Skey)
#define NEWDES96_Encipher(Skey) NEWDES96_Object_Init_With_Text_Key(Skey)

#endif /* C_once_144D66DB_5194_4393_9B79_FCE53D00D162 */








|










198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#endif
  ;

void *NEWDES96_Object_Init_With_Text_Key(char *Skey)
#ifdef _YOYO_NEWDES96_BUILTIN
  {
    byte_t key[16] = {0};
    Md5_Digest(Skey,strlen(Skey),key);
    return NEWDES96_Init(key+1,15);
  }
#endif
  ;

#define NEWDES96_Decipher(Skey) NEWDES96_Object_Init_With_Text_Key(Skey)
#define NEWDES96_Encipher(Skey) NEWDES96_Object_Init_With_Text_Key(Skey)

#endif /* C_once_144D66DB_5194_4393_9B79_FCE53D00D162 */

Changes to pefile.hc.

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
...
170
171
172
173
174
175
176
177










































178
179
180
181
182
183
184
...
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504









505
506
507
508
509
510
511
    // = 0x0001  - Reserved, must be zero.
    // = 0x0002  - Reserved, must be zero.
    // = 0x0004  - Reserved, must be zero.
    // = 0x0008  - Reserved, must be zero.
    PE_DLL_CHARACTERISTICS_DYNAMIC_BASE     = 0x0040, // DLL can be relocated at load time.
    PE_DLL_CHARACTERISTICS_FORCE_INTEGRITY  = 0x0080, // Code Integrity checks are enforced.
    PE_DLL_CHARACTERISTICS_NX_COMPAT        = 0x0100, // Image is NX compatible.
    PE_DLLCHARACTERISTICS_NO_ISOLATION      = 0x0200, // Isolation aware, but do not isolate the image.
    PE_DLLCHARACTERISTICS_NO_SEH            = 0x0400, 
      // Does not use structured exception (SE) handling. No SE handler may be called in this image.
    PE_IMAGE_DLLCHARACTERISTICS_NO_BIND     = 0x0800, // Do not bind the image.
    // = 0x1000 - Reserved, must be zero.
    PE_DLLCHARACTERISTICS_WDM_DRIVER        = 0x2000, // A WDM driver.
    PE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE = 0x8000 // Terminal Server aware.      
  };
     
enum _PE_DIRECTORY_INDEX
  {
    PE_DIRECTORY_ENTRY_EXPORT          = 0,
    PE_DIRECTORY_ENTRY_IMPORT          = 1,
    PE_DIRECTORY_ENTRY_RESOURCE        = 2,
................................................................................
    PE_DIRECTORY_ENTRY_TLS             = 9,
    PE_DIRECTORY_ENTRY_LOAD_CONFIG     = 10,
    PE_DIRECTORY_ENTRY_BOUND_IMPORT    = 11,
    PE_DIRECTORY_ENTRY_IAT             = 12,
    PE_DIRECTORY_ENTRY_DELAY_IMPORT    = 13,
    PE_DIRECTORY_ENTRY_COM_DESCRIPTOR  = 14,
  };
      










































typedef struct _PE_DOS_HEADER
  {
    ushort_t   e_magic;       // Magic number
    ushort_t   e_cblp;        // Bytes on last page of file
    ushort_t   e_cp;          // Pages in file
    ushort_t   e_crlc;        // Relocations
    ushort_t   e_cparhdr;     // Size of header in paragraphs
................................................................................
      }
      
    return 0;
  }
#endif
  ;

void *Pe_RVA_To_Ptr(void *pe, longptr_t rva)
#ifdef _YOYO_PEFILE_BUILTIN
  {
    if ( rva )
      {
        PE_SECTION_HEADER *sec = Pe_RVA_To_Section(pe,rva);
        if ( sec )
          {
            longptr_t offs = rva - sec->VirtualAddress;
            longptr_t datasize = Pe_Align_To_File(pe,sec->SizeOfRawData);
            if ( offs <= datasize )
              return (char*)pe + (sec->PointerToRawData + offs);
          }
      }
      
    return 0;
  }









#endif
  ;

void *Pe_Get_Dir_Ptr(void *pe, int idx)
#ifdef _YOYO_PEFILE_BUILTIN
  {
    return Pe_RVA_To_Ptr(pe,Pe_Get_Dir(pe,idx)->VirtualAddress);







|
|



|
|







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|










|





>
>
>
>
>
>
>
>
>







142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
...
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
    // = 0x0001  - Reserved, must be zero.
    // = 0x0002  - Reserved, must be zero.
    // = 0x0004  - Reserved, must be zero.
    // = 0x0008  - Reserved, must be zero.
    PE_DLL_CHARACTERISTICS_DYNAMIC_BASE     = 0x0040, // DLL can be relocated at load time.
    PE_DLL_CHARACTERISTICS_FORCE_INTEGRITY  = 0x0080, // Code Integrity checks are enforced.
    PE_DLL_CHARACTERISTICS_NX_COMPAT        = 0x0100, // Image is NX compatible.
    PE_DLL_CHARACTERISTICS_NO_ISOLATION     = 0x0200, // Isolation aware, but do not isolate the image.
    PE_DLL_CHARACTERISTICS_NO_SEH           = 0x0400, 
      // Does not use structured exception (SE) handling. No SE handler may be called in this image.
    PE_IMAGE_DLLCHARACTERISTICS_NO_BIND     = 0x0800, // Do not bind the image.
    // = 0x1000 - Reserved, must be zero.
    PE_DLL_CHARACTERISTICS_WDM_DRIVER       = 0x2000, // A WDM driver.
    PE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE = 0x8000 // Terminal Server aware.      
  };
     
enum _PE_DIRECTORY_INDEX
  {
    PE_DIRECTORY_ENTRY_EXPORT          = 0,
    PE_DIRECTORY_ENTRY_IMPORT          = 1,
    PE_DIRECTORY_ENTRY_RESOURCE        = 2,
................................................................................
    PE_DIRECTORY_ENTRY_TLS             = 9,
    PE_DIRECTORY_ENTRY_LOAD_CONFIG     = 10,
    PE_DIRECTORY_ENTRY_BOUND_IMPORT    = 11,
    PE_DIRECTORY_ENTRY_IAT             = 12,
    PE_DIRECTORY_ENTRY_DELAY_IMPORT    = 13,
    PE_DIRECTORY_ENTRY_COM_DESCRIPTOR  = 14,
  };

enum _PE_SCN
  {
    PE_SCN_TYPE_NO_PAD                 = 0x00000008,  // Reserved.
    PE_SCN_CNT_CODE                    = 0x00000020,  // Section contains code.
    PE_SCN_CNT_INITIALIZED_DATA        = 0x00000040,  // Section contains initialized data.
    PE_SCN_CNT_UNINITIALIZED_DATA      = 0x00000080,  // Section contains uninitialized data.
    PE_SCN_LNK_OTHER                   = 0x00000100,  // Reserved.
    PE_SCN_LNK_INFO                    = 0x00000200,  // Section contains comments or some other type of information.
    PE_SCN_LNK_REMOVE                  = 0x00000800,  // Section contents will not become part of image.
    PE_SCN_LNK_COMDAT                  = 0x00001000,  // Section contents comdat.
    PE_SCN_NO_DEFER_SPEC_EXC           = 0x00004000,  // Reset speculative exceptions handling bits in the TLB entries for this section.
    PE_SCN_GPREL                       = 0x00008000,  // Section content can be accessed relative to GP
    PE_SCN_MEM_FARDATA                 = 0x00008000,
    PE_SCN_MEM_PURGEABLE               = 0x00020000,
    PE_SCN_MEM_16BIT                   = 0x00020000,
    PE_SCN_MEM_LOCKED                  = 0x00040000,
    PE_SCN_MEM_PRELOAD                 = 0x00080000,
    PE_SCN_ALIGN_1BYTES                = 0x00100000,  //
    PE_SCN_ALIGN_2BYTES                = 0x00200000,  //
    PE_SCN_ALIGN_4BYTES                = 0x00300000,  //
    PE_SCN_ALIGN_8BYTES                = 0x00400000,  //
    PE_SCN_ALIGN_16BYTES               = 0x00500000,  // Default alignment if no others are specified.
    PE_SCN_ALIGN_32BYTES               = 0x00600000,  //
    PE_SCN_ALIGN_64BYTES               = 0x00700000,  //
    PE_SCN_ALIGN_128BYTES              = 0x00800000,  //
    PE_SCN_ALIGN_256BYTES              = 0x00900000,  //
    PE_SCN_ALIGN_512BYTES              = 0x00A00000,  //
    PE_SCN_ALIGN_1024BYTES             = 0x00B00000,  //
    PE_SCN_ALIGN_2048BYTES             = 0x00C00000,  //
    PE_SCN_ALIGN_4096BYTES             = 0x00D00000,  //
    PE_SCN_ALIGN_8192BYTES             = 0x00E00000,  //
    PE_SCN_ALIGN_MASK                  = 0x00F00000,
    PE_SCN_LNK_NRELOC_OVFL             = 0x01000000,  // Section contains extended relocations.
    PE_SCN_MEM_DISCARDABLE             = 0x02000000,  // Section can be discarded.
    PE_SCN_MEM_NOT_CACHED              = 0x04000000,  // Section is not cachable.
    PE_SCN_MEM_NOT_PAGED               = 0x08000000,  // Section is not pageable.
    PE_SCN_MEM_SHARED                  = 0x10000000,  // Section is shareable.
    PE_SCN_MEM_EXECUTE                 = 0x20000000,  // Section is executable.
    PE_SCN_MEM_READ                    = 0x40000000,  // Section is readable.
    PE_SCN_MEM_WRITE                   = 0x80000000,  // Section is writeable.
  };

typedef struct _PE_DOS_HEADER
  {
    ushort_t   e_magic;       // Magic number
    ushort_t   e_cblp;        // Bytes on last page of file
    ushort_t   e_cp;          // Pages in file
    ushort_t   e_crlc;        // Relocations
    ushort_t   e_cparhdr;     // Size of header in paragraphs
................................................................................
      }
      
    return 0;
  }
#endif
  ;

longptr_t Pe_RVA_To_Offs(void *pe, longptr_t rva)
#ifdef _YOYO_PEFILE_BUILTIN
  {
    if ( rva )
      {
        PE_SECTION_HEADER *sec = Pe_RVA_To_Section(pe,rva);
        if ( sec )
          {
            longptr_t offs = rva - sec->VirtualAddress;
            longptr_t datasize = Pe_Align_To_File(pe,sec->SizeOfRawData);
            if ( offs <= datasize )
              return sec->PointerToRawData + offs;
          }
      }
      
    return 0;
  }
#endif
  ;

void *Pe_RVA_To_Ptr(void *pe, longptr_t rva)
#ifdef _YOYO_PEFILE_BUILTIN
  {
    longptr_t offs = Pe_RVA_To_Offs(pe,rva);
    return offs ? (byte_t*)pe+offs : 0;
  }
#endif
  ;

void *Pe_Get_Dir_Ptr(void *pe, int idx)
#ifdef _YOYO_PEFILE_BUILTIN
  {
    return Pe_RVA_To_Ptr(pe,Pe_Get_Dir(pe,idx)->VirtualAddress);

Changes to random.hc.

1
2
3
4
5
6
7
8
9
10
11
12
13
..
27
28
29
30
31
32
33


34
35
36
37
38
39
40
..
44
45
46
47
48
49
50










































51
52
53


54
55
56
57
58
59
60
61
62








63
64
65
66
67

68
69
70
71
72
73
74
75
76
..
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

/*

(C)2010-2011, Alexéy Sudáchen, alexey@sudachen.name

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
................................................................................

*/

#ifndef C_once_FF657866_8205_4CAE_9D01_65B8583E9D19
#define C_once_FF657866_8205_4CAE_9D01_65B8583E9D19

#include "core.hc"



#ifdef __windoze
# include <wincrypt.h>
# ifdef _MSC_VER
#  pragma comment(lib,"advapi32.lib")
# endif
#else
................................................................................

#ifdef _YOYO_RANDOM_BUILTIN
#define _YOYO_RANDOM_EXTERN
#else
#define _YOYO_RANDOM_EXTERN extern
#endif











































void System_Random(void *bits,int count /* of bytes*/ )
#ifdef _YOYO_RANDOM_BUILTIN
  {


  #ifndef __windoze
    int i, fd = open(_YOYO_DEV_RANDOM,O_RDONLY);
    if ( fd >= 0 )
      {
        for ( i = 0; i < count; )
          {
            int rd = read(fd,bits+i,count);
            if ( rd < 0 )
              {








                close(fd);
                Yo_Raise(YOYO_ERROR_IO,
                  _YOYO_DEV_RANDOM " does not have required data: failed to read",
                  __FILE__,__LINE__);
              }

            i += rd;
            count -= rd;
          }
        close(fd);
        return;
      }
    else
      goto simulate;
  #else
................................................................................
    if ( !fCryptGenRandom(cp,count,(unsigned char*)bits) )
      goto simulate;
    if ( count >= 4 && *(unsigned*)bits == 0 )
      goto simulate;
    return;
  #endif      
  simulate:
  #ifdef _STRICT
    Yo_Raise(YOYO_ERROR_IO,_YOYO_DEV_RANDOM " is not accessable",__Yo_FILE__,__LINE__);
  #else
    if ( 1 )
      {
        static uint_t sid = 0; 
        int i;
        
        if ( !sid ) sid = (uint_t)time(0);
        for ( i = 0; i < count; i+=4 )
          {
            sid = 1664525U * sid + 1013904223U;
            memcpy((char*)bits+i,&sid,Yo_MIN(count-i,4));
          }
      }
  #endif
  }
#endif
  ;

ulong_t Random_Bits(int no)
#ifdef _YOYO_RANDOM_BUILTIN
  {
    static byte_t bits[256] = {0};
    static int bits_count = 0;
    ulong_t r = 0;
    
    STRICT_REQUIRE( no > 0 && no <= sizeof(ulong_t)*8 );
    
    __Xchg_Interlock
      while ( no )





|







 







>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



>
>
|
|




|


>
>
>
>
>
>
>
>
|
|
|
<
|
>

<







 







|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







|







1
2
3
4
5
6
7
8
9
10
11
12
13
..
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
..
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

120
121
122

123
124
125
126
127
128
129
...
143
144
145
146
147
148
149
150















151
152
153
154
155
156
157
158
159
160
161
162
163
164
165

/*

(C)2010-2011, Alexéy Sudáchen, alexey@sudachen.name

Permission is hereby granted, free of charge, to any person ornd_bcontaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
................................................................................

*/

#ifndef C_once_FF657866_8205_4CAE_9D01_65B8583E9D19
#define C_once_FF657866_8205_4CAE_9D01_65B8583E9D19

#include "core.hc"
#include "sha2.hc"
#include "md5.hc"

#ifdef __windoze
# include <wincrypt.h>
# ifdef _MSC_VER
#  pragma comment(lib,"advapi32.lib")
# endif
#else
................................................................................

#ifdef _YOYO_RANDOM_BUILTIN
#define _YOYO_RANDOM_EXTERN
#else
#define _YOYO_RANDOM_EXTERN extern
#endif

void Soft_Random(byte_t *bits, int count)
#ifdef _YOYO_RANDOM_BUILTIN
  {
    static uquad_t rnd_ct[4] = {0};
    static byte_t rnd_bits[32] = {0}; 
    static int rnd_bcont = 0;
    static int initialized = 0;
    __Xchg_Interlock
      {
        if ( !initialized )
          {
            rnd_ct[0] = ((quad_t)getpid() << 48 ) | (quad_t)time(0);
            rnd_ct[1] = 0;
            rnd_ct[2] = 0;
            rnd_ct[3] = (longptr_t)&bits;
            initialized = 1;
          }
          
        while ( count )
          {
            if ( !rnd_bcont )
              {
                rnd_ct[1] = clock();
              #ifdef _SOFTRND_ADDENTRPY  
                rnd_ct[2] = (*(quad_t*)((byte_t*)&count - 256) ^  *(quad_t*)((byte_t*)&count + 256)) + 1;
              #else
                rnd_ct[2] = (quad_t)count ^ (longptr_t)bits;
              #endif
                Md5_Digest(rnd_ct,64,rnd_bits);
                ++rnd_ct[3];
                Md5_Digest(rnd_ct,64,rnd_bits+16);
                ++rnd_ct[3];
                rnd_bcont = 32;
              }
            *bits++ = rnd_bits[--rnd_bcont];
            --count;
          }
      }
  }
#endif
  ;
  
void System_Random(void *bits,int count /* of bytes*/ )
#ifdef _YOYO_RANDOM_BUILTIN
  {
  #ifdef _SOFTRND
    goto simulate;
  #elif !defined __windoze
    int i, fd = open(_YOYO_DEV_RANDOM,O_RDONLY|O_NONBLOCK);
    if ( fd >= 0 )
      {
        for ( i = 0; i < count; )
          {
            int rd = read(fd,bits+i,count-i);
            if ( rd < 0 )
              {
                if ( rd == EAGAIN )
                  {
                    Soft_Random(bits+i,count-i);
                    break;
                  }
                else
                  {
                    char *err = strerror(errno);
                    close(fd);
                    __Raise_Format(YOYO_ERROR_IO,
                      (_YOYO_DEV_RANDOM " does not have required data: %s",err));

                  }
              }
            i += rd;

          }
        close(fd);
        return;
      }
    else
      goto simulate;
  #else
................................................................................
    if ( !fCryptGenRandom(cp,count,(unsigned char*)bits) )
      goto simulate;
    if ( count >= 4 && *(unsigned*)bits == 0 )
      goto simulate;
    return;
  #endif      
  simulate:
    Soft_Random(bits,count);















  }
#endif
  ;

ulong_t Random_Bits(int no)
#ifdef _YOYO_RANDOM_BUILTIN
  {
    static byte_t bits[128] = {0};
    static int bits_count = 0;
    ulong_t r = 0;
    
    STRICT_REQUIRE( no > 0 && no <= sizeof(ulong_t)*8 );
    
    __Xchg_Interlock
      while ( no )

Changes to sha1.hc.

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47


48
49
50
51














52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
...
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
...
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
...
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
...
326
327
328
329
330
331
332
333





























































































334
335
*/

#ifndef C_once_1B3E01E2_7457_494E_A17C_3A12388FC4AF
#define C_once_1B3E01E2_7457_494E_A17C_3A12388FC4AF

#include "core.hc"

typedef struct _YOYO_SHA1_SIGNER
  {
    uint_t state[5];   /* state (ABCDE) */
    uint_t count[2];   /* number of bits, modulo 2^64 (lsb first) */
    int    finished;
    byte_t buffer[64]; /* input buffer */
  } YOYO_SHA1_SIGNER;



void *Sha1_Clone(YOYO_SHA1_SIGNER *sha1)
#ifdef _YOYO_SHA1_BUILTIN
  {
    return Yo_Object_Clone(sizeof(YOYO_SHA1_SIGNER),sha1);














  }
#endif
  ;

void *Sha1_Init()
#ifdef _YOYO_SHA1_BUILTIN
  {
    static YOYO_FUNCTABLE funcs[] = 
      { {0},
        {Oj_Clone_OjMID, Sha1_Clone },
        {0}};
    
    YOYO_SHA1_SIGNER *sha1 = Yo_Object(sizeof(YOYO_SHA1_SIGNER),funcs);

    sha1->state[0] = 0x67452301; 
    sha1->state[1] = 0xefcdab89; 
    sha1->state[2] = 0x98badcfe; 
    sha1->state[3] = 0x10325476;
    sha1->state[4] = 0xc3d2e1f0;

    return sha1;
  }
#endif
  ;

void Sha1_Update(YOYO_SHA1_SIGNER *sha1, void *data, int len);
void *Sha1_Finish(YOYO_SHA1_SIGNER *sha1, void *digest);

#define YOYO_SHA1_INITIALIZER {{0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0},{0},0,{0}}

void *Sha1_Sign_Data(void *data, int len, void *digest)
#ifdef _YOYO_SHA1_BUILTIN
  {
    YOYO_SHA1_SIGNER sha1 = YOYO_SHA1_INITIALIZER;
    Sha1_Update(&sha1,data,len);
    return Sha1_Finish(&sha1,digest);
  }
#endif
  ;

void *Sha1_Sign_Sign_Data(void *data, int len, void *digest)
#ifdef _YOYO_SHA1_BUILTIN
  {
    byte_t tmp[20];
    YOYO_SHA1_SIGNER sha1 = YOYO_SHA1_INITIALIZER;
    Sha1_Sign_Data(data,len,tmp);
    Sha1_Update(&sha1,tmp,20);
    Sha1_Update(&sha1,data,len);
    return Sha1_Finish(&sha1,digest);
  }
#endif
  ;

#define Sha1_Digest_Of(Data,Len) Sha1_Sign_Data(Data,Len,0)

#ifdef _YOYO_SHA1_BUILTIN


#if 0
  #if defined _X86 || defined __i386 || defined __x86_64
    #define Sha1_Internal_Encode memcpy
    #define Sha1_Internal_Decode memcpy
  #else
    void Sha1_Internal_Encode(byte_t *output, uint_t *input, uint_t len) 
      {
        uint_t i, j;

        for (i = 0, j = 0; j < len; i++, j += 4) 
          {
            output[j]   = (byte_t)(input[i] & 0xff);
            output[j+1] = (byte_t)((input[i] >> 8) & 0xff);
            output[j+2] = (byte_t)((input[i] >> 16) & 0xff);
            output[j+3] = (byte_t)((input[i] >> 24) & 0xff);
          }
      }

    void Sha1_Internal_Decode(uint_t *output, byte_t *input, uint_t len)
      {
        uint_t i, j;

        for (i = 0, j = 0; j < len; i++, j += 4)
          output[i] = ((uint_t)input[j]) | (((uint_t)input[j+1]) << 8) |
            (((uint_t)input[j+2]) << 16) | (((uint_t)input[j+3]) << 24);
      }
  #endif

#else
    void Sha1_Internal_Encode(byte_t *output, uint_t *input, uint_t len) 
      {
        uint_t i, j;

        for (i = 0, j = 0; j < len; i++, j += 4) 
          {
            output[j+0] = (byte_t)(input[i] >> 24);
            output[j+1] = (byte_t)(input[i] >> 16);
            output[j+2] = (byte_t)(input[i] >> 8);
            output[j+3] = (byte_t)(input[i]);
          }
      }

    void Sha1_Internal_Decode(uint_t *output, byte_t *input, uint_t len)
      {
        uint_t i, j;
        for (i = 0, j = 0; j < len; i++, j += 4)
          output[i] = ((uint_t)input[j+3]) | (((uint_t)input[j+2]) << 8) |
            (((uint_t)input[j+1]) << 16) | (((uint_t)input[j+0]) << 24);
      }
#endif

  #define ROTATE_LEFT(x,n) (((x) << (n)) | ((x) >> (32-(n))))
  #define R(t) (x[t&0x0f] = ROTATE_LEFT( \
                      x[(t- 3)&0x0f] \
                    ^ x[(t- 8)&0x0f] \
                    ^ x[(t-14)&0x0f] \
                    ^ x[(t   )&0x0f], \
................................................................................
  #define G(x,y,z) (x ^ y ^ z)
  #define GG(a,b,c,d,e,q) e += ROTATE_LEFT(a,5) + G(b,c,d) + 0x6ed9eba1u + q; b = ROTATE_LEFT(b,30)
  #define H(x,y,z) ((x & y) | (z & (x | y)))
  #define HH(a,b,c,d,e,q) e += ROTATE_LEFT(a,5) + H(b,c,d) + 0x8f1bbcdcu + q; b = ROTATE_LEFT(b,30)
  #define I(x,y,z) (x ^ y ^ z)
  #define II(a,b,c,d,e,q) e += ROTATE_LEFT(a,5) + I(b,c,d) + 0xca62c1d6u + q; b = ROTATE_LEFT(b,30)

  void Sha1_Internal_Transform(YOYO_SHA1_SIGNER *sha1, void *block)
    {
      uint_t *state = sha1->state;
      uint_t a = state[0], b = state[1], c = state[2], d = state[3], e = state[4], x[16];

      Sha1_Internal_Decode(x, block, 64);

      FF( a, b, c, d, e, x[0]  );
................................................................................
  #undef I
  #undef ROTATE_LEFT
  #undef FF
  #undef GG
  #undef HH
  #undef II

  void Sha1_Update(YOYO_SHA1_SIGNER *sha1, void *input, int input_length)
    {      
      int i, index, partLen;
      uint_t *count = sha1->count;
      index = (uint_t)((count[0] >> 3) & 0x3F);
      if ((count[0] += ((uint_t)input_length << 3)) < ((uint_t)input_length << 3))
        count[1]++;
      count[1] += ((uint_t)input_length >> 29);
................................................................................
          index = 0;
        }
      else
        i = 0;
      memcpy(&sha1->buffer[index],&((byte_t*)input)[i],input_length-i);
    }

  void *Sha1_Finish(YOYO_SHA1_SIGNER *sha1, void *digest)
    {
      if ( !sha1->finished )
        {
          static byte_t PADDING[64] = {
            0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
          };
          byte_t bits[8];
          uint_t index, padLen;
          Sha1_Internal_Encode(bits, sha1->count+1, 4);
          Sha1_Internal_Encode(bits+4, sha1->count, 4);
          index = (uint_t)((sha1->count[0] >> 3) & 0x3f);
          padLen = (index < 56) ? (56 - index) : (120 - index);
          Sha1_Update(sha1, PADDING, padLen);
          Sha1_Update(sha1, bits, 8);
................................................................................
        }
      if ( !digest ) digest = __Malloc(20);
      Sha1_Internal_Encode(digest, sha1->state, 20);
      return digest;
    }

#endif /* _YOYO_SHA1_BUILTIN */






























































































#endif /* C_once_1B3E01E2_7457_494E_A17C_3A12388FC4AF */








|





|

>
>
|


|
>
>
>
>
>
>
>
>
>
>
>
>
>
>












|
<
<
<
<
<
<
<
|




|
|

<
<
|


|






|



|
|







|



<
<
<
<
<
<
|
|
|

|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
|
|
|
|

|
|
|
|
|
|
|
<







 







|







 







|







 







|








|







 








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80







81
82
83
84
85
86
87
88


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115






116
117
118
119
120
121
























122
123
124
125
126
127
128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
...
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
...
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
...
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
...
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
*/

#ifndef C_once_1B3E01E2_7457_494E_A17C_3A12388FC4AF
#define C_once_1B3E01E2_7457_494E_A17C_3A12388FC4AF

#include "core.hc"

typedef struct _YOYO_SHA1
  {
    uint_t state[5];   /* state (ABCDE) */
    uint_t count[2];   /* number of bits, modulo 2^64 (lsb first) */
    int    finished;
    byte_t buffer[64]; /* input buffer */
  } YOYO_SHA1;

#define YOYO_SHA1_INITIALIZER {{0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0},{0},0,{0}}

void *Sha1_Clone(YOYO_SHA1 *sha1)
#ifdef _YOYO_SHA1_BUILTIN
  {
    return __Clone(sizeof(YOYO_SHA1),sha1);
  }
#endif
  ;

void *Sha1_Start(YOYO_SHA1 *sha1)
#ifdef _YOYO_SHA1_BUILTIN
  {
    memset(sha1,0,sizeof(*sha1));
    sha1->state[0] = 0x67452301; 
    sha1->state[1] = 0xefcdab89; 
    sha1->state[2] = 0x98badcfe; 
    sha1->state[3] = 0x10325476;
    sha1->state[4] = 0xc3d2e1f0;
    return sha1;
  }
#endif
  ;

void *Sha1_Init()
#ifdef _YOYO_SHA1_BUILTIN
  {
    static YOYO_FUNCTABLE funcs[] = 
      { {0},
        {Oj_Clone_OjMID, Sha1_Clone },
        {0}};
    
    YOYO_SHA1 *sha1 = __Object(sizeof(YOYO_SHA1),funcs);







    return Sha1_Start(sha1);
  }
#endif
  ;

void Sha1_Update(YOYO_SHA1 *sha1, void *data, int len);
void *Sha1_Finish(YOYO_SHA1 *sha1, void *digest);



void *Sha1_Digest(void *data, int len, void *digest)
#ifdef _YOYO_SHA1_BUILTIN
  {
    YOYO_SHA1 sha1 = YOYO_SHA1_INITIALIZER;
    Sha1_Update(&sha1,data,len);
    return Sha1_Finish(&sha1,digest);
  }
#endif
  ;

void *Sha1_Digest_Digest(void *data, int len, void *digest)
#ifdef _YOYO_SHA1_BUILTIN
  {
    byte_t tmp[20];
    YOYO_SHA1 sha1 = YOYO_SHA1_INITIALIZER;
    Sha1_Digest(data,len,tmp);
    Sha1_Update(&sha1,tmp,20);
    Sha1_Update(&sha1,data,len);
    return Sha1_Finish(&sha1,digest);
  }
#endif
  ;

#define Sha1_Digest_Of(Data,Len) Sha1_Digest(Data,Len,0)

#ifdef _YOYO_SHA1_BUILTIN







  void Sha1_Internal_Encode(byte_t *output, uint_t *input, uint_t len) 
    {
      uint_t i, j;

      for (i = 0, j = 0; j < len; i++, j += 4) 
        {
























          output[j+0] = (byte_t)(input[i] >> 24);
          output[j+1] = (byte_t)(input[i] >> 16);
          output[j+2] = (byte_t)(input[i] >> 8);
          output[j+3] = (byte_t)(input[i]);
        }
    }

  void Sha1_Internal_Decode(uint_t *output, byte_t *input, uint_t len)
    {
      uint_t i, j;
      for (i = 0, j = 0; j < len; i++, j += 4)
        output[i] = ((uint_t)input[j+3]) | (((uint_t)input[j+2]) << 8) |
          (((uint_t)input[j+1]) << 16) | (((uint_t)input[j+0]) << 24);
    }


  #define ROTATE_LEFT(x,n) (((x) << (n)) | ((x) >> (32-(n))))
  #define R(t) (x[t&0x0f] = ROTATE_LEFT( \
                      x[(t- 3)&0x0f] \
                    ^ x[(t- 8)&0x0f] \
                    ^ x[(t-14)&0x0f] \
                    ^ x[(t   )&0x0f], \
................................................................................
  #define G(x,y,z) (x ^ y ^ z)
  #define GG(a,b,c,d,e,q) e += ROTATE_LEFT(a,5) + G(b,c,d) + 0x6ed9eba1u + q; b = ROTATE_LEFT(b,30)
  #define H(x,y,z) ((x & y) | (z & (x | y)))
  #define HH(a,b,c,d,e,q) e += ROTATE_LEFT(a,5) + H(b,c,d) + 0x8f1bbcdcu + q; b = ROTATE_LEFT(b,30)
  #define I(x,y,z) (x ^ y ^ z)
  #define II(a,b,c,d,e,q) e += ROTATE_LEFT(a,5) + I(b,c,d) + 0xca62c1d6u + q; b = ROTATE_LEFT(b,30)

  void Sha1_Internal_Transform(YOYO_SHA1 *sha1, void *block)
    {
      uint_t *state = sha1->state;
      uint_t a = state[0], b = state[1], c = state[2], d = state[3], e = state[4], x[16];

      Sha1_Internal_Decode(x, block, 64);

      FF( a, b, c, d, e, x[0]  );
................................................................................
  #undef I
  #undef ROTATE_LEFT
  #undef FF
  #undef GG
  #undef HH
  #undef II

  void Sha1_Update(YOYO_SHA1 *sha1, void *input, int input_length)
    {      
      int i, index, partLen;
      uint_t *count = sha1->count;
      index = (uint_t)((count[0] >> 3) & 0x3F);
      if ((count[0] += ((uint_t)input_length << 3)) < ((uint_t)input_length << 3))
        count[1]++;
      count[1] += ((uint_t)input_length >> 29);
................................................................................
          index = 0;
        }
      else
        i = 0;
      memcpy(&sha1->buffer[index],&((byte_t*)input)[i],input_length-i);
    }

  void *Sha1_Finish(YOYO_SHA1 *sha1, void *digest)
    {
      if ( !sha1->finished )
        {
          static byte_t PADDING[64] = {
            0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
          };
          byte_t bits[8] = {0};
          uint_t index, padLen;
          Sha1_Internal_Encode(bits, sha1->count+1, 4);
          Sha1_Internal_Encode(bits+4, sha1->count, 4);
          index = (uint_t)((sha1->count[0] >> 3) & 0x3f);
          padLen = (index < 56) ? (56 - index) : (120 - index);
          Sha1_Update(sha1, PADDING, padLen);
          Sha1_Update(sha1, bits, 8);
................................................................................
        }
      if ( !digest ) digest = __Malloc(20);
      Sha1_Internal_Encode(digest, sha1->state, 20);
      return digest;
    }

#endif /* _YOYO_SHA1_BUILTIN */

typedef struct _YOYO_HMAC_SHA1
  {
    YOYO_SHA1 sha1;
    byte_t ipad[64];
    byte_t opad[64];
  } YOYO_HMAC_SHA1;

void *Hmac_Sha1_Clone(YOYO_HMAC_SHA1 *hmac)
#ifdef _YOYO_SHA1_BUILTIN
  {
    return __Clone(sizeof(YOYO_HMAC_SHA1),hmac);
  }
#endif
  ;

void *Hmac_Sha1_Start(YOYO_HMAC_SHA1 *hmac, void *key, int key_len)
#ifdef _YOYO_SHA1_BUILTIN
  {
    int i;
    byte_t sum[20];
    
    if ( key_len > 64 )
      {
        Sha1_Start(&hmac->sha1);
        Sha1_Update(&hmac->sha1,key,key_len);
        Sha1_Finish(&hmac->sha1,sum);
        key = sum;
        key_len = 20;
      }
    
    memset( hmac->ipad, 0x36, 64 );
    memset( hmac->opad, 0x5C, 64 );
    
    for( i = 0; i < key_len; ++i )
      {
        hmac->ipad[i] = (byte_t)( hmac->ipad[i] ^ ((byte_t*)key)[i] );
        hmac->opad[i] = (byte_t)( hmac->opad[i] ^ ((byte_t*)key)[i] );
      }
    
    Sha1_Start(&hmac->sha1);
    Sha1_Update(&hmac->sha1,hmac->ipad,64);
    
    memset(sum,0,sizeof(sum));
    return hmac;
  }
#endif
  ;

void *Hmac_Sha1_Init(void *key, int key_len)
#ifdef _YOYO_SHA1_BUILTIN
  {
    static YOYO_FUNCTABLE funcs[] = 
      { {0},
        {Oj_Clone_OjMID, Hmac_Sha1_Clone },
        {0}};
    
    YOYO_HMAC_SHA1 *sha1 = __Object(sizeof(YOYO_HMAC_SHA1),funcs);
    return Hmac_Sha1_Start(sha1,key,key_len);
  }
#endif
  ;

void Hmac_Sha1_Update(YOYO_HMAC_SHA1 *hmac, void *input, int input_length)
#ifdef _YOYO_SHA1_BUILTIN
  {
    Sha1_Update(&hmac->sha1,input,input_length);
  }
#endif
  ;

void *Hmac_Sha1_Finish(YOYO_HMAC_SHA1 *hmac, void *digest)
#ifdef _YOYO_SHA1_BUILTIN
  {
    byte_t tmpb[20];
    Sha1_Finish(&hmac->sha1,tmpb);
    Sha1_Start(&hmac->sha1);
    Sha1_Update(&hmac->sha1,&hmac->opad,64);
    Sha1_Update(&hmac->sha1,tmpb,20);
    memset(tmpb,0,20);
    return Sha1_Finish(&hmac->sha1,digest);
  }
#endif
  ;

void Hmac_Sha1_Reset(YOYO_HMAC_SHA1 *hmac)
#ifdef _YOYO_SHA1_BUILTIN
  {
    Sha1_Start(&hmac->sha1);
    Sha1_Update(&hmac->sha1,hmac->ipad,64);
  }
#endif
  ;

#endif /* C_once_1B3E01E2_7457_494E_A17C_3A12388FC4AF */

Changes to sha2.hc.

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

















52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
...
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
...
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
...
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
...
298
299
300
301
302
303
304
305





























































































306
307
*/

#ifndef C_once_18F7EAA7_0DBC_4720_BA4A_7E0B1A9A5B1E
#define C_once_18F7EAA7_0DBC_4720_BA4A_7E0B1A9A5B1E

#include "core.hc"

typedef struct _YOYO_SHA2_SIGNER
  {
    uint_t state[8];   /* state (ABCDEFGH) */
    uint_t count[2];   /* number of bits, modulo 2^64 (lsb first) */
    int    finished;
    byte_t buffer[64]; /* input buffer */
  } YOYO_SHA2_SIGNER;

void *Sha2_Clone(YOYO_SHA2_SIGNER *sha2)
#ifdef _YOYO_SHA2_BUILTIN
  {
    return Yo_Object_Clone(sizeof(YOYO_SHA2_SIGNER),sha2);

















  }
#endif
  ;

void *Sha2_Init()
#ifdef _YOYO_SHA2_BUILTIN
  {
    static YOYO_FUNCTABLE funcs[] = 
      { {0},
        {Oj_Clone_OjMID, Sha2_Clone },
        {0}};
    
    YOYO_SHA2_SIGNER *sha2 = Yo_Object(sizeof(YOYO_SHA2_SIGNER),funcs);

    sha2->state[0] = 0x6a09e667;
    sha2->state[1] = 0xbb67ae85;
    sha2->state[2] = 0x3c6ef372;
    sha2->state[3] = 0xa54ff53a;
    sha2->state[4] = 0x510e527f;
    sha2->state[5] = 0x9b05688c;
    sha2->state[6] = 0x1f83d9ab;
    sha2->state[7] = 0x5be0cd19;
    
    
    return sha2;
  }
#endif
  ;

void Sha2_Update(YOYO_SHA2_SIGNER *sha2, void *data, int len);
void *Sha2_Finish(YOYO_SHA2_SIGNER *sha2, void *digest);

#define YOYO_SHA2_INITIALIZER {\
  {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, \
   0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19} \
   ,{0},0,{0}}

void *Sha2_Sign_Data(void *data, int len, void *digest)
#ifdef _YOYO_SHA2_BUILTIN
  {
    YOYO_SHA2_SIGNER sha2 = YOYO_SHA2_INITIALIZER;
    Sha2_Update(&sha2,data,len);
    return Sha2_Finish(&sha2,digest);
  }
#endif
  ;

void *Sha2_Sign_Sign_Data(void *data, int len, void *digest)
#ifdef _YOYO_SHA2_BUILTIN
  {
    byte_t tmp[32];
    YOYO_SHA2_SIGNER sha2 = YOYO_SHA2_INITIALIZER;
    Sha2_Sign_Data(data,len,tmp);
    Sha2_Update(&sha2,tmp,32);
    Sha2_Update(&sha2,data,len);
    return Sha2_Finish(&sha2,digest);
  }
#endif
  ;

#define Sha2_Digest_Of(Data,Len) Sha2_Sign_Data(Data,Len,0)

#ifdef _YOYO_SHA2_BUILTIN

  void Sha2_Internal_Encode(byte_t *output, uint_t *input, uint_t len) 
    {
      uint_t i, j;

................................................................................
  #define F(a,b,c,d,e,f,g,h,x,K) \
  { \
      uint_t foo = h + S3(e) + F1(e,f,g) + K + x; \
      uint_t bar = S2(a) + F0(a,b,c); \
      d += foo; h = foo + bar; \
  }
  
  void Sha2_Internal_Transform(YOYO_SHA2_SIGNER *sha2, void *block)
    {
      uint_t *state = sha2->state;
      uint_t 
        a = state[0], 
        b = state[1], 
        c = state[2], 
        d = state[3], 
................................................................................
  #undef S2
  #undef S3
  #undef F0
  #undef F1
  #undef SHR
  #undef ROTR

  void Sha2_Update(YOYO_SHA2_SIGNER *sha2, void *input, int input_length)
    {      
      int i, index, partLen;
      uint_t *count = sha2->count;
      index = (uint_t)((count[0] >> 3) & 0x3F);
      if ((count[0] += ((uint_t)input_length << 3)) < ((uint_t)input_length << 3))
        count[1]++;
      count[1] += ((uint_t)input_length >> 29);
................................................................................
          index = 0;
        }
      else
        i = 0;
      memcpy(&sha2->buffer[index],&((byte_t*)input)[i],input_length-i);
    }

  void *Sha2_Finish(YOYO_SHA2_SIGNER *sha2, void *digest)
    {
      if ( !sha2->finished )
        {
          static byte_t PADDING[64] = {
            0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
................................................................................
        }
      if ( !digest ) digest = __Malloc(32);
      Sha2_Internal_Encode(digest, sha2->state, 32);
      return digest;
    }

#endif /* _YOYO_SHA2_BUILTIN */






























































































#endif /* C_once_18F7EAA7_0DBC_4720_BA4A_7E0B1A9A5B1E */








|





|

|


|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>












|
<
<
<
<
<
<
<
<
<
<
<
|




|
|






|


|






|



|
|







|







 







|







 







|







 







|







 








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81











82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
...
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
...
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
...
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
*/

#ifndef C_once_18F7EAA7_0DBC_4720_BA4A_7E0B1A9A5B1E
#define C_once_18F7EAA7_0DBC_4720_BA4A_7E0B1A9A5B1E

#include "core.hc"

typedef struct _YOYO_SHA2
  {
    uint_t state[8];   /* state (ABCDEFGH) */
    uint_t count[2];   /* number of bits, modulo 2^64 (lsb first) */
    int    finished;
    byte_t buffer[64]; /* input buffer */
  } YOYO_SHA2;

void *Sha2_Clone(YOYO_SHA2 *sha2)
#ifdef _YOYO_SHA2_BUILTIN
  {
    return __Clone(sizeof(YOYO_SHA2),sha2);
  }
#endif
  ;

void *Sha2_Start(YOYO_SHA2 *sha2)
#ifdef _YOYO_SHA2_BUILTIN
  {
    memset(sha2,0,sizeof(*sha2));
    sha2->state[0] = 0x6a09e667;
    sha2->state[1] = 0xbb67ae85;
    sha2->state[2] = 0x3c6ef372;
    sha2->state[3] = 0xa54ff53a;
    sha2->state[4] = 0x510e527f;
    sha2->state[5] = 0x9b05688c;
    sha2->state[6] = 0x1f83d9ab;
    sha2->state[7] = 0x5be0cd19;
    return sha2;
  }
#endif
  ;

void *Sha2_Init()
#ifdef _YOYO_SHA2_BUILTIN
  {
    static YOYO_FUNCTABLE funcs[] = 
      { {0},
        {Oj_Clone_OjMID, Sha2_Clone },
        {0}};
    
    YOYO_SHA2 *sha2 = __Object(sizeof(YOYO_SHA2),funcs);











    return Sha2_Start(sha2);
  }
#endif
  ;

void Sha2_Update(YOYO_SHA2 *sha2, void *data, int len);
void *Sha2_Finish(YOYO_SHA2 *sha2, void *digest);

#define YOYO_SHA2_INITIALIZER {\
  {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, \
   0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19} \
   ,{0},0,{0}}

void *Sha2_Digest(void *data, int len, void *digest)
#ifdef _YOYO_SHA2_BUILTIN
  {
    YOYO_SHA2 sha2 = YOYO_SHA2_INITIALIZER;
    Sha2_Update(&sha2,data,len);
    return Sha2_Finish(&sha2,digest);
  }
#endif
  ;

void *Sha2_Digest_Digest(void *data, int len, void *digest)
#ifdef _YOYO_SHA2_BUILTIN
  {
    byte_t tmp[32];
    YOYO_SHA2 sha2 = YOYO_SHA2_INITIALIZER;
    Sha2_Digest(data,len,tmp);
    Sha2_Update(&sha2,tmp,32);
    Sha2_Update(&sha2,data,len);
    return Sha2_Finish(&sha2,digest);
  }
#endif
  ;

#define Sha2_Digest_Of(Data,Len) Sha2_Digest(Data,Len,0)

#ifdef _YOYO_SHA2_BUILTIN

  void Sha2_Internal_Encode(byte_t *output, uint_t *input, uint_t len) 
    {
      uint_t i, j;

................................................................................
  #define F(a,b,c,d,e,f,g,h,x,K) \
  { \
      uint_t foo = h + S3(e) + F1(e,f,g) + K + x; \
      uint_t bar = S2(a) + F0(a,b,c); \
      d += foo; h = foo + bar; \
  }
  
  void Sha2_Internal_Transform(YOYO_SHA2 *sha2, void *block)
    {
      uint_t *state = sha2->state;
      uint_t 
        a = state[0], 
        b = state[1], 
        c = state[2], 
        d = state[3], 
................................................................................
  #undef S2
  #undef S3
  #undef F0
  #undef F1
  #undef SHR
  #undef ROTR

  void Sha2_Update(YOYO_SHA2 *sha2, void *input, int input_length)
    {      
      int i, index, partLen;
      uint_t *count = sha2->count;
      index = (uint_t)((count[0] >> 3) & 0x3F);
      if ((count[0] += ((uint_t)input_length << 3)) < ((uint_t)input_length << 3))
        count[1]++;
      count[1] += ((uint_t)input_length >> 29);
................................................................................
          index = 0;
        }
      else
        i = 0;
      memcpy(&sha2->buffer[index],&((byte_t*)input)[i],input_length-i);
    }

  void *Sha2_Finish(YOYO_SHA2 *sha2, void *digest)
    {
      if ( !sha2->finished )
        {
          static byte_t PADDING[64] = {
            0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
................................................................................
        }
      if ( !digest ) digest = __Malloc(32);
      Sha2_Internal_Encode(digest, sha2->state, 32);
      return digest;
    }

#endif /* _YOYO_SHA2_BUILTIN */

typedef struct _YOYO_HMAC_SHA2
  {
    YOYO_SHA2 sha2;
    byte_t ipad[64];
    byte_t opad[64];
  } YOYO_HMAC_SHA2;

void *Hmac_Sha2_Clone(YOYO_HMAC_SHA2 *hmac)
#ifdef _YOYO_SHA2_BUILTIN
  {
    return __Clone(sizeof(YOYO_HMAC_SHA2),hmac);
  }
#endif
  ;

void *Hmac_Sha2_Start(YOYO_HMAC_SHA2 *hmac, void *key, int key_len)
#ifdef _YOYO_SHA2_BUILTIN
  {
    int i;
    byte_t sum[32];
    
    if ( key_len > 64 )
      {
        Sha2_Start(&hmac->sha2);
        Sha2_Update(&hmac->sha2,key,key_len);
        Sha2_Finish(&hmac->sha2,sum);
        key = sum;
        key_len = 32;
      }
    
    memset( hmac->ipad, 0x36, 64 );
    memset( hmac->opad, 0x5C, 64 );
    
    for( i = 0; i < key_len; ++i )
      {
        hmac->ipad[i] = (byte_t)( hmac->ipad[i] ^ ((byte_t*)key)[i] );
        hmac->opad[i] = (byte_t)( hmac->opad[i] ^ ((byte_t*)key)[i] );
      }
    
    Sha2_Start(&hmac->sha2);
    Sha2_Update(&hmac->sha2,hmac->ipad,64);
    
    memset(sum,0,sizeof(sum));
    return hmac;
  }
#endif
  ;

void *Hmac_Sha2_Init(void *key, int key_len)
#ifdef _YOYO_SHA2_BUILTIN
  {
    static YOYO_FUNCTABLE funcs[] = 
      { {0},
        {Oj_Clone_OjMID, Hmac_Sha2_Clone },
        {0}};
    
    YOYO_HMAC_SHA2 *sha2 = __Object(sizeof(YOYO_HMAC_SHA2),funcs);
    return Hmac_Sha2_Start(sha2,key,key_len);
  }
#endif
  ;

void Hmac_Sha2_Update(YOYO_HMAC_SHA2 *hmac, void *input, int input_length)
#ifdef _YOYO_SHA2_BUILTIN
  {
    Sha2_Update(&hmac->sha2,input,input_length);
  }
#endif
  ;

void *Hmac_Sha2_Finish(YOYO_HMAC_SHA2 *hmac, void *digest)
#ifdef _YOYO_SHA2_BUILTIN
  {
    byte_t tmpb[32];
    Sha2_Finish(&hmac->sha2,tmpb);
    Sha2_Start(&hmac->sha2);
    Sha2_Update(&hmac->sha2,&hmac->opad,64);
    Sha2_Update(&hmac->sha2,tmpb,32);
    memset(tmpb,0,32);
    return Sha2_Finish(&hmac->sha2,digest);
  }
#endif
  ;

void Hmac_Sha2_Reset(YOYO_HMAC_SHA2 *hmac)
#ifdef _YOYO_SHA2_BUILTIN
  {
    Sha2_Start(&hmac->sha2);
    Sha2_Update(&hmac->sha2,hmac->ipad,64);
  }
#endif
  ;

#endif /* C_once_18F7EAA7_0DBC_4720_BA4A_7E0B1A9A5B1E */

Changes to string.hc.

1420
1421
1422
1423
1424
1425
1426



















1427
1428
      ret[i] = S[(L-i)-1];
    ret[L] = 0;
    return ret;
  }
#endif
  ;
  



















#endif /* C_once_0ED387CD_668B_44C3_9D91_A6336A2F5F48 */








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
      ret[i] = S[(L-i)-1];
    ret[L] = 0;
    return ret;
  }
#endif
  ;
  
wchar_t *Str_Unicode_Transform_Npl(wchar_t *S, int L, wchar_t (*transform)(wchar_t))
#ifdef _YOYO_STRING_BUILTIN  
  {
    int i;
    wchar_t *ret;
    if ( L < 0 ) L = S?wcslen(S):0;
    ret = __Malloc_Npl(L*sizeof(wchar_t)+1);
    for ( i = 0; i < L; ++i )
      ret[i] = transform(S[i]);
    return ret;
  }
#endif
  ;

#define Str_Unicode_Upper(S,L) ((wchar_t*)__Pool(Str_Unicode_Upper_Npl(S,L)))
#define Str_Unicode_Upper_Npl(S,L) Str_Unicode_Transform_Npl(S,L,towupper)
#define Str_Unicode_Lower(S,L) ((wchar_t*)__Pool(Str_Unicode_Lower_Npl(S,L)))
#define Str_Unicode_Lower_Npl(S,L) Str_Unicode_Transform_Npl(S,L,towlower)

#endif /* C_once_0ED387CD_668B_44C3_9D91_A6336A2F5F48 */

Changes to tests/aes.c.

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
            puts("usage: ./aes <filename>");
            exit(-1);
          }
        bf = Oj_Read_All(Cfile_Open(Prog_Argument(0),"r"));
      }
    
    System_Random(passwd+strlen(passwd),4);
    Sha2_Sign_Data(passwd,sizeof(passwd),sign);
    
    Aes_Init_Encipher_Static(&ctxe,sign,256);
    Aes_Init_Decipher_Static(&ctxd,sign,256);
    bbf = Buffer_Copy(bf->at,bf->count);
    for ( i = 0; i+16 < bf->count; i+= 16 )
      Aes_Encrypt16(&ctxe,bbf->at+i);
    __Auto_Release 







|







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
            puts("usage: ./aes <filename>");
            exit(-1);
          }
        bf = Oj_Read_All(Cfile_Open(Prog_Argument(0),"r"));
      }
    
    System_Random(passwd+strlen(passwd),4);
    Sha2_Digest(passwd,sizeof(passwd),sign);
    
    Aes_Init_Encipher_Static(&ctxe,sign,256);
    Aes_Init_Decipher_Static(&ctxd,sign,256);
    bbf = Buffer_Copy(bf->at,bf->count);
    for ( i = 0; i+16 < bf->count; i+= 16 )
      Aes_Encrypt16(&ctxe,bbf->at+i);
    __Auto_Release 

Added tests/genrsa.py.





































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import sys, os, os.path
os.chdir(os.path.abspath(os.path.dirname(__file__)))
import simplersa

N = 1
QL = 4096
Q = [ simplersa.gen_key_pair_(512,1097,2000,300,0) for i in range(N) ]

NN = 1
for q in (Q):
    NN = NN + 1
    print " public = "+str(q[0])    
    print " private = "+str(q[1])    
    print " module = "+str(q[2])    

#print "\n*/"
#print "RSA_VALUE_TYPE partner_keys_E[] = {"
#for q in (Q):
#    S = ""
#    k = q[1] # priv
#    for i in range(512/(4*8)):
#        S += "0x%08x," % (k&0x0ffffffffL)
#        k >>= 32
#    print "  {"+S+"},"    
#print "  };"
#print "RSA_VALUE_TYPE partner_keys_N[] = {"
#for q in (Q):
#    S = ""
#    k = q[2] # mod
#    for i in range(512/(4*8)):
#        S += "0x%08x," % (k&0x0ffffffffL)
#        k >>= 32
#    print "  {"+S+"},"    
#print "  };"

Added tests/hmacmd5.c.







































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

#include "../libyoyo.hc"


/*
 * RFC 2202 test vectors
 */
byte_t Data_Key[7][26] =
  {
    { "\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B" },
    { "Jefe" },
    { "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA" },
    { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10"
      "\x11\x12\x13\x14\x15\x16\x17\x18\x19" },
    { "\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C" },
    { "" }, /* 0xAA 80 times */
    { "" }
  };

int Data_Keylen[7] =
  {
    16, 4, 16, 25, 16, 80, 80
  };

byte_t Data_Buf[7][74] =
  {
    { "Hi There" },
    { "what do ya want for nothing?" },
    { "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" },
    { "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" },
    { "Test With Truncation" },
    { "Test Using Larger Than Block-Size Key - Hash Key First" },
    { "Test Using Larger Than Block-Size Key and Larger"
      " Than One Block-Size Data" }
  };

int Data_Buflen[7] =
  {
    8, 28, 50, 50, 20, 54, 73
  };

byte_t Data_Sum[7][16] =
  {
    { 0x92, 0x94, 0x72, 0x7A, 0x36, 0x38, 0xBB, 0x1C,
      0x13, 0xF4, 0x8E, 0xF8, 0x15, 0x8B, 0xFC, 0x9D },
    { 0x75, 0x0C, 0x78, 0x3E, 0x6A, 0xB0, 0xB5, 0x03,
      0xEA, 0xA8, 0x6E, 0x31, 0x0A, 0x5D, 0xB7, 0x38 },
    { 0x56, 0xBE, 0x34, 0x52, 0x1D, 0x14, 0x4C, 0x88,
      0xDB, 0xB8, 0xC7, 0x33, 0xF0, 0xE8, 0xB3, 0xF6 },
    { 0x69, 0x7E, 0xAF, 0x0A, 0xCA, 0x3A, 0x3A, 0xEA,
      0x3A, 0x75, 0x16, 0x47, 0x46, 0xFF, 0xAA, 0x79 },
    { 0x56, 0x46, 0x1E, 0xF2, 0x34, 0x2E, 0xDC, 0x00,
      0xF9, 0xBA, 0xB9, 0x95 },
    { 0x6B, 0x1A, 0xB7, 0xFE, 0x4B, 0xD7, 0xBF, 0x8F,
      0x0B, 0x62, 0xE6, 0xCE, 0x61, 0xB9, 0xD0, 0xCD },
    { 0x6F, 0x63, 0x0F, 0xAD, 0x67, 0xCD, 0xA0, 0xEE,
      0x1F, 0xB1, 0xF5, 0x62, 0xDB, 0x3A, 0xA5, 0x3E }
  };


int main(int argc, char **argv)
  {
    byte_t buf[80];
    int i, verbose, buflen;
    YOYO_HMAC_MD5 ctx;
    
    Prog_Init(argc,argv,"?|h,l",PROG_EXIT_ON_ERROR);
    
    verbose = Prog_Has_Opt("l");
    
    for( i = 0; i < 7; i++ )
      {
        if( verbose )
            printf( "  HMAC-MD5 test #%d: ", i + 1 );

        if( i == 5 || i == 6 )
          {
            memset( buf, '\xAA', buflen = 80 );
            Hmac_Md5_Start( &ctx, buf, buflen );
          }
        else
            Hmac_Md5_Start( &ctx, Data_Key[i],
                                  Data_Keylen[i] );

        Hmac_Md5_Update( &ctx, Data_Buf[i],
                               Data_Buflen[i] );

        Hmac_Md5_Finish( &ctx, buf );

        buflen = ( i == 4 ) ? 12 : 16;

        if( memcmp( buf, Data_Sum[i], buflen ) != 0 )
          {
            if( verbose )
                puts("failed");
            return 1;
          }
        else
          {
            if( verbose )
              puts("passed");
          }
      }
      
    return 0;
  }

Added tests/hmacsha1.c.















































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

#include "../libyoyo.hc"


/*
 * RFC 2202 test vectors
 */
 
byte_t Data_Key[7][26] =
{
    { "\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B"
      "\x0B\x0B\x0B\x0B" },
    { "Jefe" },
    { "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
      "\xAA\xAA\xAA\xAA" },
    { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10"
      "\x11\x12\x13\x14\x15\x16\x17\x18\x19" },
    { "\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C"
      "\x0C\x0C\x0C\x0C" },
    { "" }, /* 0xAA 80 times */
    { "" }
};

int Data_Keylen[7] =
{
    20, 4, 20, 25, 20, 80, 80
};

byte_t Data_Buf[7][74] =
{
    { "Hi There" },
    { "what do ya want for nothing?" },
    { "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" },
    { "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" },
    { "Test With Truncation" },
    { "Test Using Larger Than Block-Size Key - Hash Key First" },
    { "Test Using Larger Than Block-Size Key and Larger"
      " Than One Block-Size Data" }
};

int Data_Buflen[7] =
{
    8, 28, 50, 50, 20, 54, 73
};

byte_t Data_Sum[7][20] =
{
    { 0xB6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64, 0xE2, 0x8B,
      0xC0, 0xB6, 0xFB, 0x37, 0x8C, 0x8E, 0xF1, 0x46, 0xBE, 0x00 },
    { 0xEF, 0xFC, 0xDF, 0x6A, 0xE5, 0xEB, 0x2F, 0xA2, 0xD2, 0x74,
      0x16, 0xD5, 0xF1, 0x84, 0xDF, 0x9C, 0x25, 0x9A, 0x7C, 0x79 },
    { 0x12, 0x5D, 0x73, 0x42, 0xB9, 0xAC, 0x11, 0xCD, 0x91, 0xA3,
      0x9A, 0xF4, 0x8A, 0xA1, 0x7B, 0x4F, 0x63, 0xF1, 0x75, 0xD3 },
    { 0x4C, 0x90, 0x07, 0xF4, 0x02, 0x62, 0x50, 0xC6, 0xBC, 0x84,
      0x14, 0xF9, 0xBF, 0x50, 0xC8, 0x6C, 0x2D, 0x72, 0x35, 0xDA },
    { 0x4C, 0x1A, 0x03, 0x42, 0x4B, 0x55, 0xE0, 0x7F, 0xE7, 0xF2,
      0x7B, 0xE1 },
    { 0xAA, 0x4A, 0xE5, 0xE1, 0x52, 0x72, 0xD0, 0x0E, 0x95, 0x70,
      0x56, 0x37, 0xCE, 0x8A, 0x3B, 0x55, 0xED, 0x40, 0x21, 0x12 },
    { 0xE8, 0xE9, 0x9D, 0x0F, 0x45, 0x23, 0x7D, 0x78, 0x6D, 0x6B,
      0xBA, 0xA7, 0x96, 0x5C, 0x78, 0x08, 0xBB, 0xFF, 0x1A, 0x91 }
};


int main(int argc, char **argv)
  {
    byte_t buf[80];
    int i, verbose, buflen;
    YOYO_HMAC_SHA1 ctx;
    
    Prog_Init(argc,argv,"?|h,l",PROG_EXIT_ON_ERROR);
    
    verbose = Prog_Has_Opt("l");
    
    for( i = 0; i < 7; i++ )
      {
        if( verbose )
            printf( "  HMAC-SHA-1 test #%d: ", i + 1 );

        if( i == 5 || i == 6 )
          {
            memset( buf, '\xAA', buflen = 80 );
            Hmac_Sha1_Start( &ctx, buf, buflen );
          }
        else
            Hmac_Sha1_Start( &ctx, Data_Key[i],
                                   Data_Keylen[i] );

        Hmac_Sha1_Update( &ctx, Data_Buf[i],
                                Data_Buflen[i] );

        Hmac_Sha1_Finish( &ctx, buf );

        buflen = ( i == 4 ) ? 12 : 20;

        if( memcmp( buf, Data_Sum[i], buflen ) != 0 )
          {
            if( verbose )
                puts("failed");
            return 1;
          }
        else
          {
            if( verbose )
              puts("passed");
          }
      }
      
    return 0;
  }

Added tests/hmacsha2.c.













































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

#include "../libyoyo.hc"

/*
 * RFC 4231 test vectors
 */
 
byte_t Data_Key[7][26] =
  {
    { "\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B"
      "\x0B\x0B\x0B\x0B" },
    { "Jefe" },
    { "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
      "\xAA\xAA\xAA\xAA" },
    { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10"
      "\x11\x12\x13\x14\x15\x16\x17\x18\x19" },
    { "\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C"
      "\x0C\x0C\x0C\x0C" },
    { "" }, /* 0xAA 131 times */
    { "" }
  };

int Data_Keylen[7] =
  {
    20, 4, 20, 25, 20, 131, 131
  };

byte_t Data_Buf[7][153] =
  {
    { "Hi There" },
    { "what do ya want for nothing?" },
    { "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" },
    { "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
      "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" },
    { "Test With Truncation" },
    { "Test Using Larger Than Block-Size Key - Hash Key First" },
    { "This is a test using a larger than block-size key "
      "and a larger than block-size data. The key needs to "
      "be hashed before being used by the HMAC algorithm." }
  };

int Data_Buflen[7] =
  {
    8, 28, 50, 50, 20, 54, 152
  };

byte_t Data_Sum[14][32] =
  {
    /*
     * HMAC-SHA-256 test vectors
     */
    { 0xB0, 0x34, 0x4C, 0x61, 0xD8, 0xDB, 0x38, 0x53,
      0x5C, 0xA8, 0xAF, 0xCE, 0xAF, 0x0B, 0xF1, 0x2B,
      0x88, 0x1D, 0xC2, 0x00, 0xC9, 0x83, 0x3D, 0xA7,
      0x26, 0xE9, 0x37, 0x6C, 0x2E, 0x32, 0xCF, 0xF7 },
    { 0x5B, 0xDC, 0xC1, 0x46, 0xBF, 0x60, 0x75, 0x4E,
      0x6A, 0x04, 0x24, 0x26, 0x08, 0x95, 0x75, 0xC7,
      0x5A, 0x00, 0x3F, 0x08, 0x9D, 0x27, 0x39, 0x83,
      0x9D, 0xEC, 0x58, 0xB9, 0x64, 0xEC, 0x38, 0x43 },
    { 0x77, 0x3E, 0xA9, 0x1E, 0x36, 0x80, 0x0E, 0x46,
      0x85, 0x4D, 0xB8, 0xEB, 0xD0, 0x91, 0x81, 0xA7,
      0x29, 0x59, 0x09, 0x8B, 0x3E, 0xF8, 0xC1, 0x22,
      0xD9, 0x63, 0x55, 0x14, 0xCE, 0xD5, 0x65, 0xFE },
    { 0x82, 0x55, 0x8A, 0x38, 0x9A, 0x44, 0x3C, 0x0E,
      0xA4, 0xCC, 0x81, 0x98, 0x99, 0xF2, 0x08, 0x3A,
      0x85, 0xF0, 0xFA, 0xA3, 0xE5, 0x78, 0xF8, 0x07,
      0x7A, 0x2E, 0x3F, 0xF4, 0x67, 0x29, 0x66, 0x5B },
    { 0xA3, 0xB6, 0x16, 0x74, 0x73, 0x10, 0x0E, 0xE0,
      0x6E, 0x0C, 0x79, 0x6C, 0x29, 0x55, 0x55, 0x2B },
    { 0x60, 0xE4, 0x31, 0x59, 0x1E, 0xE0, 0xB6, 0x7F,
      0x0D, 0x8A, 0x26, 0xAA, 0xCB, 0xF5, 0xB7, 0x7F,
      0x8E, 0x0B, 0xC6, 0x21, 0x37, 0x28, 0xC5, 0x14,
      0x05, 0x46, 0x04, 0x0F, 0x0E, 0xE3, 0x7F, 0x54 },
    { 0x9B, 0x09, 0xFF, 0xA7, 0x1B, 0x94, 0x2F, 0xCB,
      0x27, 0x63, 0x5F, 0xBC, 0xD5, 0xB0, 0xE9, 0x44,
      0xBF, 0xDC, 0x63, 0x64, 0x4F, 0x07, 0x13, 0x93,
      0x8A, 0x7F, 0x51, 0x53, 0x5C, 0x3A, 0x35, 0xE2 }
  };


int main(int argc, char **argv)
  {
    byte_t buf[256];
    int i, verbose, buflen;
    YOYO_HMAC_SHA2 ctx;
    
    Prog_Init(argc,argv,"?|h,l",PROG_EXIT_ON_ERROR);
    
    verbose = Prog_Has_Opt("l");
    
    for( i = 0; i < 7; i++ )
      {
        if( verbose )
            printf( "  HMAC-SHA-2 test #%d: ", i + 1 );

        if( i == 5 || i == 6 )
          {
            memset( buf, '\xAA', buflen = 131 );
            Hmac_Sha2_Start( &ctx, buf, buflen );
          }
        else
            Hmac_Sha2_Start( &ctx, Data_Key[i],
                                   Data_Keylen[i] );

        Hmac_Sha2_Update( &ctx, Data_Buf[i],
                                Data_Buflen[i] );

        Hmac_Sha2_Finish( &ctx, buf );

        buflen = ( i == 4 ) ? 16 : 32;

        if( memcmp( buf, Data_Sum[i], buflen ) != 0 )
          {
            if( verbose )
                puts("failed");
            return 1;
          }
        else
          {
            if( verbose )
              puts("passed");
          }
      }
      
    return 0;
  }

Changes to tests/md5.c.

12
13
14
15
16
17
18
19
20
21
22
    if ( !Prog_Arguments_Count() )
      {
        puts("usage: ./md5 <filename>");
        exit(-1);
      }
    
    bf = Oj_Read_All(Cfile_Open(Prog_Argument(0),"r"));
    Md5_Sign_Data(bf->at,bf->count,sign);
    puts(Str_Hex_Encode(sign,16));
  }








|



12
13
14
15
16
17
18
19
20
21
22
    if ( !Prog_Arguments_Count() )
      {
        puts("usage: ./md5 <filename>");
        exit(-1);
      }
    
    bf = Oj_Read_All(Cfile_Open(Prog_Argument(0),"r"));
    Md5_Digest(bf->at,bf->count,sign);
    puts(Str_Hex_Encode(sign,16));
  }

Changes to tests/rsa.c.

1
2
3
4
5
6
7
8
9

#define _LIBYOYO
#include "../libyoyo.hc"

enum { MAX_ITER_COUNT = 3 };

int main(int argc, char **argv)
  {
    int bits, i;

<







1

2
3
4
5
6
7
8


#include "../libyoyo.hc"

enum { MAX_ITER_COUNT = 3 };

int main(int argc, char **argv)
  {
    int bits, i;

Changes to tests/sha1.c.

1
2
3

























4
5





6
7



8

9
10




11
12

13
14
15


16

17
18
19
20



21


























#include "../libyoyo.hc"


























int main(int argc, char **argv)
  {





    YOYO_BUFFER *bf;
    byte_t sign[20] = {0};



    

    
    Prog_Init(argc,argv,"?|h,l",PROG_EXIT_ON_ERROR);





    if ( !Prog_Arguments_Count() )

      {
        puts("usage: ./sha1 <filename>");
        exit(-1);


      }

    
    bf = Oj_Read_All(Cfile_Open(Prog_Argument(0),"r"));
    Sha1_Sign_Data(bf->at,bf->count,sign);
    puts(Str_Hex_Encode(sign,20));



  }




























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


>
>
>
>
>
|
|
>
>
>
|
>
|
<
>
>
>
>
|
<
>
|
<
<
>
>
|
>
|
<
<
<
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

44
45
46
47
48

49
50


51
52
53
54
55



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

#include "../libyoyo.hc"

/*
 * FIPS-180-1 test vectors
 */
byte_t Data_Buf[3][57] = 
{
    { "abc" },
    { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
    { "" }
};

int Data_Buflen[3] =
{
    3, 56, 1000
};

byte_t Data_Sum[3][20] =
{
    { 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E,
      0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D },
    { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE,
      0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 },
    { 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E,
      0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F }
};

int main(int argc, char **argv)
  {

    Prog_Init(argc,argv,"?|h,l",PROG_EXIT_ON_ERROR);

    if ( Prog_Arguments_Count() )
      {
        YOYO_BUFFER *bf;
        byte_t sign[20] = {0};
        bf = Oj_Read_All(Cfile_Open(Prog_Argument(0),"r"));
        Sha1_Digest(bf->at,bf->count,sign);
        puts(Str_Hex_Encode(sign,20));
      }
    else
      {

        int i, j, buflen;
        byte_t buf[1000];
        int verbose = Prog_Has_Opt("l");
        YOYO_SHA1 ctx;
        

        for ( i = 0; i < 3; i++ )
          {


            if ( verbose )
                printf( "  SHA-1 test #%d: ", i + 1 );

            Sha1_Start( &ctx );




            if ( i == 2 )
              {
                  memset( buf, 'a', buflen = 1000 );

                  for ( j = 0; j < 1000; j++ )
                      Sha1_Update( &ctx, buf, buflen );
              }
            else
                Sha1_Update( &ctx,Data_Buf[i],
                                  Data_Buflen[i] );

            Sha1_Finish( &ctx, buf );

            if ( memcmp( buf,Data_Sum[i], 20 ) != 0 )
              {
                if ( verbose )
                    puts("failed");
                return 1;
              }
            else
              {
                if( verbose )
                    puts("passed");
              }
          }
      }
      
    return 0;
  }

Changes to tests/sha2.c.

1
2
3
































4
5





6
7



8

9
10




11
12

13
14
15


16

17
18
19
20



21


22























#include "../libyoyo.hc"

































int main(int argc, char **argv)
  {





    YOYO_BUFFER *bf;
    byte_t sign[32] = {0};



    

    
    Prog_Init(argc,argv,"?|h,l",PROG_EXIT_ON_ERROR);





    if ( !Prog_Arguments_Count() )

      {
        puts("usage: ./sha2 <filename>");
        exit(-1);


      }

    
    bf = Oj_Read_All(Cfile_Open(Prog_Argument(0),"r"));
    Sha2_Sign_Data(bf->at,bf->count,sign);
    puts(Str_Hex_Encode(sign,32));



  }




























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


>
>
>
>
>
|
|
>
>
>
|
>
|
<
>
>
>
>
|
<
>
|
<
<
>
>
|
>
|
<
<
<
>
>
>
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

51
52
53
54
55

56
57


58
59
60
61
62



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

#include "../libyoyo.hc"

byte_t Data_Buf[3][57] = 
  {
    { "abc" },
    { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
    { "" }
  };

int Data_Buflen[3] =
  {
    3, 56, 1000
  };

byte_t Data_Sum[6][32] =
  {
    /*
     * SHA-256 test vectors
     */
    { 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA,
      0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23,
      0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C,
      0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD },
    { 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8,
      0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39,
      0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67,
      0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 },
    { 0xCD, 0xC7, 0x6E, 0x5C, 0x99, 0x14, 0xFB, 0x92,
      0x81, 0xA1, 0xC7, 0xE2, 0x84, 0xD7, 0x3E, 0x67,
      0xF1, 0x80, 0x9A, 0x48, 0xA4, 0x97, 0x20, 0x0E,
      0x04, 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0 }
  };


int main(int argc, char **argv)
  {

    Prog_Init(argc,argv,"?|h,l",PROG_EXIT_ON_ERROR);

    if ( Prog_Arguments_Count() )
      {
        YOYO_BUFFER *bf;
        byte_t sign[32] = {0};
        bf = Oj_Read_All(Cfile_Open(Prog_Argument(0),"r"));
        Sha2_Digest(bf->at,bf->count,sign);
        puts(Str_Hex_Encode(sign,32));
      }
    else
      {

        int i, j, buflen;
        byte_t buf[1000];
        int verbose = Prog_Has_Opt("l");
        YOYO_SHA2 ctx;
        

        for ( i = 0; i < 3; i++ )
          {


            if ( verbose )
                printf( "  SHA-2 test #%d: ", i + 1 );

            Sha2_Start( &ctx );




            if ( i == 2 )
              {
                  memset( buf, 'a', buflen = 1000 );

                  for ( j = 0; j < 1000; j++ )
                      Sha2_Update( &ctx, buf, buflen );
              }
            else
                Sha2_Update( &ctx,Data_Buf[i],
                                  Data_Buflen[i] );

            Sha2_Finish( &ctx, buf );

            if ( memcmp( buf,Data_Sum[i], 32 ) != 0 )
              {
                if ( verbose )
                    puts("failed");
                return 1;
              }
            else
              {
                if( verbose )
                    puts("passed");
              }
          }
      }
      
    return 0;
  }

Added tests/simplersa.py.

















































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# 
# Simple RSA
# Copyright (c) 2007, Alexey Sudachen
# 

from random import random
from os import urandom
import sys,struct

_there_is_no_more = "there is no more then 500 primes"

first_500_prime_values = [
 2       ,3       ,5       ,7       ,11      ,13      ,17      ,19      ,23      ,29
,31      ,37      ,41      ,43      ,47      ,53      ,59      ,61      ,67      ,71
,73      ,79      ,83      ,89      ,97      ,101     ,103     ,107     ,109     ,113
,127     ,131     ,137     ,139     ,149     ,151     ,157     ,163     ,167     ,173
,179     ,181     ,191     ,193     ,197     ,199     ,211     ,223     ,227     ,229
,233     ,239     ,241     ,251     ,257     ,263     ,269     ,271     ,277     ,281
,283     ,293     ,307     ,311     ,313     ,317     ,331     ,337     ,347     ,349
,353     ,359     ,367     ,373     ,379     ,383     ,389     ,397     ,401     ,409
,419     ,421     ,431     ,433     ,439     ,443     ,449     ,457     ,461     ,463
,467     ,479     ,487     ,491     ,499     ,503     ,509     ,521     ,523     ,541
,547     ,557     ,563     ,569     ,571     ,577     ,587     ,593     ,599     ,601
,607     ,613     ,617     ,619     ,631     ,641     ,643     ,647     ,653     ,659
,661     ,673     ,677     ,683     ,691     ,701     ,709     ,719     ,727     ,733
,739     ,743     ,751     ,757     ,761     ,769     ,773     ,787     ,797     ,809
,811     ,821     ,823     ,827     ,829     ,839     ,853     ,857     ,859     ,863
,877     ,881     ,883     ,887     ,907     ,911     ,919     ,929     ,937     ,941
,947     ,953     ,967     ,971     ,977     ,983     ,991     ,997     ,1009    ,1013
,1019    ,1021    ,1031    ,1033    ,1039    ,1049    ,1051    ,1061    ,1063    ,1069
,1087    ,1091    ,1093    ,1097    ,1103    ,1109    ,1117    ,1123    ,1129    ,1151
,1153    ,1163    ,1171    ,1181    ,1187    ,1193    ,1201    ,1213    ,1217    ,1223
,1229    ,1231    ,1237    ,1249    ,1259    ,1277    ,1279    ,1283    ,1289    ,1291
,1297    ,1301    ,1303    ,1307    ,1319    ,1321    ,1327    ,1361    ,1367    ,1373
,1381    ,1399    ,1409    ,1423    ,1427    ,1429    ,1433    ,1439    ,1447    ,1451
,1453    ,1459    ,1471    ,1481    ,1483    ,1487    ,1489    ,1493    ,1499    ,1511
,1523    ,1531    ,1543    ,1549    ,1553    ,1559    ,1567    ,1571    ,1579    ,1583
,1597    ,1601    ,1607    ,1609    ,1613    ,1619    ,1621    ,1627    ,1637    ,1657
,1663    ,1667    ,1669    ,1693    ,1697    ,1699    ,1709    ,1721    ,1723    ,1733
,1741    ,1747    ,1753    ,1759    ,1777    ,1783    ,1787    ,1789    ,1801    ,1811
,1823    ,1831    ,1847    ,1861    ,1867    ,1871    ,1873    ,1877    ,1879    ,1889
,1901    ,1907    ,1913    ,1931    ,1933    ,1949    ,1951    ,1973    ,1979    ,1987
,1993    ,1997    ,1999    ,2003    ,2011    ,2017    ,2027    ,2029    ,2039    ,2053
,2063    ,2069    ,2081    ,2083    ,2087    ,2089    ,2099    ,2111    ,2113    ,2129
,2131    ,2137    ,2141    ,2143    ,2153    ,2161    ,2179    ,2203    ,2207    ,2213
,2221    ,2237    ,2239    ,2243    ,2251    ,2267    ,2269    ,2273    ,2281    ,2287
,2293    ,2297    ,2309    ,2311    ,2333    ,2339    ,2341    ,2347    ,2351    ,2357
,2371    ,2377    ,2381    ,2383    ,2389    ,2393    ,2399    ,2411    ,2417    ,2423
,2437    ,2441    ,2447    ,2459    ,2467    ,2473    ,2477    ,2503    ,2521    ,2531
,2539    ,2543    ,2549    ,2551    ,2557    ,2579    ,2591    ,2593    ,2609    ,2617
,2621    ,2633    ,2647    ,2657    ,2659    ,2663    ,2671    ,2677    ,2683    ,2687
,2689    ,2693    ,2699    ,2707    ,2711    ,2713    ,2719    ,2729    ,2731    ,2741
,2749    ,2753    ,2767    ,2777    ,2789    ,2791    ,2797    ,2801    ,2803    ,2819
,2833    ,2837    ,2843    ,2851    ,2857    ,2861    ,2879    ,2887    ,2897    ,2903
,2909    ,2917    ,2927    ,2939    ,2953    ,2957    ,2963    ,2969    ,2971    ,2999
,3001    ,3011    ,3019    ,3023    ,3037    ,3041    ,3049    ,3061    ,3067    ,3079
,3083    ,3089    ,3109    ,3119    ,3121    ,3137    ,3163    ,3167    ,3169    ,3181
,3187    ,3191    ,3203    ,3209    ,3217    ,3221    ,3229    ,3251    ,3253    ,3257
,3259    ,3271    ,3299    ,3301    ,3307    ,3313    ,3319    ,3323    ,3329    ,3331
,3343    ,3347    ,3359    ,3361    ,3371    ,3373    ,3389    ,3391    ,3407    ,3413
,3433    ,3449    ,3457    ,3461    ,3463    ,3467    ,3469    ,3491    ,3499    ,3511
,3517    ,3527    ,3529    ,3533    ,3539    ,3541    ,3547    ,3557    ,3559    ,3571
]

ferma_prime_values = [ 3, 5, 17, 257, 65537 ]

def modexp(p,e,mod):
    r = 1
    t = p
    while e:
        if e & 1:
            r = (r * t) % mod
        e = e >> 1
        t = (t * t) % mod
    return r

def invmod(p,mod):
    b = mod
    c = p
    i = 0
    j = 1
    while c:
        x = b / c
        y = b % c
        b = c
        c = y
        i, j = j, (i-(j*x))
    if i < 0: i += mod
    return i

def ferma_prime_test(p,q=32):
    if q > len(first_500_prime_values)+1:
        raise ValueError(_there_is_no_more)
    for i in xrange(1,q):
        if modexp(first_500_prime_values[i],p-1,p) != 1:
            return False
    return True

def is_prime(p,q=32):
    if q > len(first_500_prime_values)+1:
        raise ValueError(_there_is_no_more)
    if not ferma_prime_test(p,q): return False
    return True

def gen_prime(bits,q=32):
    if q > len(first_500_prime_values)+1:
        raise ValueError(_there_is_no_more)
    while True:
        r = 2L
        for i in xrange(bits-3):
            r = (r << 1) + long(random() * 2)
        r = (r << 1) + 1
        for i in xrange(q):
            if not is_prime(r,q):
                r += 2
            else:
                return r

def first_prime_with(p,s=1):
    if s >= len(first_500_prime_values):
        raise ValueError(_there_is_no_more)
    for i in xrange(s,len(first_500_prime_values)):
        x = first_500_prime_values[i]
        if p%x != 0 : return x
    raise ValueError("nonprime")

def gen_key_pair_(xl,pl,ql,s,fp=50):
    n = 0
    xlL = (1L<<xl*8) - 1
    xlR = (1L<<(xl*8-1))
    while n > xlL or n < xlR:
        p = gen_prime(pl,s)
        q = gen_prime(ql,s)
        n = p * q
    phi = (p-1)*(q-1)
    if not fp:
        e = gen_prime(xl*8/3,s)
    else: 
        f=int(random()*(len(first_500_prime_values)-fp-1)+fp)
        e = first_prime_with(phi,f)
    d = invmod(e,phi)
    return e,d,n

def gen_key_pair_128():
    return gen_key_pair_(16,33,96,300)

def gen_key_pair_256():
    return gen_key_pair_(32,65,192,300)

def gen_key_pair_512():
    return gen_key_pair_(64,123,390,300)

def cipher_N(lx,k,key,n):
    ln =lx * 8;
    m = (1L << ln) -1;
    r = 0
    x = k & m
    r = modexp(x,key,n)
    return r

def cipher_S(lx,s,key,n):
    k = 0L
    if len(s)%lx != 0: s = s + '\0'*(lx-len(s)%lx)
    for i in s: k = (k << 8) + ord(i)
    r = cipher_N(lx,k,key,n)
    s = ''
    while lx: 
        s = chr(r&0xff) + s
        r = r >> 8
        lx = lx - 1
    return s

def cipher_128S(s,key,n): 
    return cipher_S(16,s,key,n)

def cipher_256S(s,key,n): 
    return cipher_S(32,s,key,n)

def cipher_512S(s,key,n): 
    return cipher_S(64,s,key,n)

def encrypt_L_encode(lx,s,Sx=False):
    bits = 0L
    bits_cnt = 0
    if Sx:
        s = struct.pack(">H",len(s)) + s
    else:
        s = struct.pack(">i",len(s)) + s
    r = ''
    while len(s):
        if len(s) > lx:
            ss = s[0:lx]
            s = s[lx:]
        else:
            ss = s
            s = ''
        hi = ord(ss[0])
        if bits_cnt % 8 == 7 : bits_cnt += 1
        if hi & 0x80:
            ss = chr(hi&0x7f) + ss[1:]
            bits |= (1L << bits_cnt)
        bits_cnt += 1
        r = r + ss
    r_bits = ''
    #print hex(bits),bits_cnt
    while bits_cnt > 0:
        r_bits = r_bits + chr(bits&0xff)
        bits_cnt -= 8
        bits >>= 8
    r = r + r_bits
    return r

def encrypt_L(lx,s,key,n,Sx=False):
    s = encrypt_L_encode(lx,s,Sx)
    r = ''
    while len(s):
        if len(s) > lx:
            ss = s[0:lx]
            s = s[lx:]
        else:
            ss = s
            s = ''
        r = r + cipher_S(lx,ss,key,n)
    return r

def encrypt_128L(s,key,n,Sx=False): 
    return encrypt_L(16,s,key,n,Sx)

def encrypt_256L(s,key,n,Sx=False): 
    return encrypt_L(32,s,key,n,Sx)

def encrypt_512L(s,key,n,Sx=False): 
    return encrypt_L(64,s,key,n,Sx)

def decrypt_L_decode(lx,s,Sx=False):
    bits = 0L
    bits_cnt = 0
    if Sx:
        sl = struct.unpack(">H",s[0:2])[0]
        sbits = s[2+sl:]
        s = s[0:sl+2]
    else:
        sl = struct.unpack(">i",s[0:4])[0]
        sbits = s[4+sl:]
        s = s[0:sl+4]
    
    bits = 0L
    bits_cnt = 0
    r = ''
    for i in sbits:
        bits |= long(ord(i)) << bits_cnt
        bits_cnt += 8
    #print hex(bits),bits_cnt
    bits_cnt = 0
    while len(s):
        if len(s) > lx:
            ss = s[0:lx]
            s = s[lx:]
        else:
            ss = s
            s = ''
        if bits_cnt % 8 == 7 : bits_cnt += 1
        if bits & (1L << bits_cnt): ss = chr(ord(ss[0])|0x80) + ss[1:]
        bits_cnt += 1
        r = r + ss
    if Sx:
        return r[2:]
    else:
        return r[4:]

def decrypt_L(lx,s,key,n,Sx=False):
    r = ''
    while len(s):
        if len(s) > lx:
            ss = s[0:lx]
            s = s[lx:]
        else:
            ss = s
            s = ''
        r = r + cipher_S(lx,ss,key,n)
    r = decrypt_L_decode(lx,r,Sx)
    return r

def decrypt_128L(s,key,n,Sx=False): 
    return decrypt_L(16,s,key,n,Sx)

def decrypt_256L(s,key,n,Sx=False): 
    return decrypt_L(32,s,key,n,Sx)

def decrypt_512L(s,key,n,Sx=False):
    return decrypt_L(64,s,key,n,Sx)


if __name__ == '__main__':
    for i in range(1):
        pub,pri,n = gen_key_pair_128()
        for j in range(100):
            print '--- %d:%d -----' %(i,j)
            s = urandom(156)
            r = encrypt_128L(s,pub,n)
            v = decrypt_128L(r,pri,n)
            if v != s:
                print ''
                print 'test step %d:'%i
                print 'S:',repr(s)
                print 'R:',repr(r)    
                print 'V:',repr(v)
                print "test failed!"
                sys.exit(-1)
            else:
                print 'S:'+repr(s)
                print 'E:'+repr(r)

Changes to winreg.hc.

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
            __Format("failed to query value '%s' of '%s': error %08x", (opt?opt:""),o->name,err));

        if ( ltype != REG_SZ )
          __Raise(YOYO_ERROR_IO,
            Yo_Format("failed to query value '%s' of '%s': is not string value",(opt?opt:""),o->name));

        //buf = Yo_Malloc((L+1)*sizeof(wchar_t));
        buf = Yo_Malloc(L+1);
        buf[L/sizeof(wchar_t)] = 0;
        
        if ( ERROR_SUCCESS == (err=RegQueryValueExW(o->hkey,name,0,&ltype,(LPBYTE)buf,&L)) )
          ret = Str_Unicode_To_Utf8(buf);
        else
          if ( err != ERROR_FILE_NOT_FOUND )
          __Raise(YOYO_ERROR_IO,







|







80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
            __Format("failed to query value '%s' of '%s': error %08x", (opt?opt:""),o->name,err));

        if ( ltype != REG_SZ )
          __Raise(YOYO_ERROR_IO,
            Yo_Format("failed to query value '%s' of '%s': is not string value",(opt?opt:""),o->name));

        //buf = Yo_Malloc((L+1)*sizeof(wchar_t));
        buf = Yo_Malloc(L+2);
        buf[L/sizeof(wchar_t)] = 0;
        
        if ( ERROR_SUCCESS == (err=RegQueryValueExW(o->hkey,name,0,&ltype,(LPBYTE)buf,&L)) )
          ret = Str_Unicode_To_Utf8(buf);
        else
          if ( err != ERROR_FILE_NOT_FOUND )
          __Raise(YOYO_ERROR_IO,

Changes to xdata.hc.

1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
    return 0;
  }
#endif
  ;
  
/*
  be carrefull when assume non-null result as succeeded
  if empty buffer adding empty string retvalue will be 0
*/
char *Xnode_Query_Str_Bf(YOYO_BUFFER *bf, YOYO_XNODE *n, char *query)
#ifdef _YOYO_XDATA_BUILTIN
  {
    YOYO_XVALUE *value = Xnode_Query_Value(n,query);
    return Xvalue_Str_Bf(value,bf);
  }







|







1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
    return 0;
  }
#endif
  ;
  
/*
  be carrefull when assume non-null result as succeeded
  if add empty string to empty buffer, retvalue will be 0
*/
char *Xnode_Query_Str_Bf(YOYO_BUFFER *bf, YOYO_XNODE *n, char *query)
#ifdef _YOYO_XDATA_BUILTIN
  {
    YOYO_XVALUE *value = Xnode_Query_Value(n,query);
    return Xvalue_Str_Bf(value,bf);
  }