- Timestamp:
- Feb 17, 2019, 2:41:49 PM (6 years ago)
- Location:
- trunk/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bignum.c
r454 r544 425 425 { 426 426 DIGIT *a_ptr, *b_ptr; 427 int retval = 0; 427 428 428 429 if (a->dgs_used == b->dgs_used) … … 437 438 if (a_ptr < a->dp) 438 439 { 439 return 0;440 return retval; 440 441 } 441 442 else 442 443 { 443 return (*a_ptr > *b_ptr) ? 1 : -1; 444 } 444 if (retval == 0) 445 retval = (*a_ptr > *b_ptr) ? 1 : -1; 446 } 447 return retval; 445 448 } 446 449 return (a->dgs_used > b->dgs_used) ? 1 : -1; -
trunk/src/cutest_slib.c
r248 r544 58 58 } 59 59 60 void Test_sl_ts_strncmp (CuTest *tc) { 61 char one[64], two[64]; 62 int res; 63 64 strcpy(one, "foo"); 65 strcpy(two, "foo"); 66 res = sl_ts_strncmp(one, two, 3); 67 CuAssertIntEquals(tc, 0, res); 68 69 strcpy(one, "fox"); 70 strcpy(two, "foo"); 71 res = sl_ts_strncmp(one, two, 2); 72 CuAssertIntEquals(tc, 0, res); 73 74 strcpy(one, "f9o"); 75 strcpy(two, "foo"); 76 res = sl_ts_strncmp(one, two, 3); 77 CuAssertTrue(tc, 0 != res); 78 79 } 80 60 81 void Test_sl_strcasecmp (CuTest *tc) { 61 82 char one[64], two[64]; -
trunk/src/sh_calls.c
r509 r544 51 51 #include "samhain.h" 52 52 #include "sh_error.h" 53 #include "sh_calls.h"54 53 #include "sh_ipvx.h" 55 54 #include "sh_sub.h" -
trunk/src/sh_srp.c
r474 r544 48 48 #define bignum MP_INT 49 49 50 inline 50 static 51 51 int big_create (bignum * a) 52 52 { … … 55 55 } 56 56 57 inline 57 static 58 58 int big_zerop (bignum * a) 59 59 { … … 69 69 } 70 70 71 inline 71 static 72 72 int big_trunc (bignum * a, bignum * b, bignum * q, bignum *r) 73 73 { … … 76 76 } 77 77 78 inline 78 static 79 79 int big_exptmod (bignum * a, bignum * b, bignum * c, bignum *d) 80 80 { … … 136 136 } 137 137 138 inline138 static 139 139 int big_add(bignum * a, bignum * b, bignum * c) 140 140 { … … 143 143 } 144 144 145 inline145 static 146 146 int big_sub(bignum * a, bignum * b, bignum * c) 147 147 { … … 150 150 } 151 151 152 inline152 static 153 153 int big_mul(bignum * a, bignum * b, bignum * c) 154 154 { … … 157 157 } 158 158 159 inline159 static 160 160 int big_greaterp(bignum * a, bignum * b) 161 161 { … … 163 163 } 164 164 165 inline165 static 166 166 int big_set_big(bignum * a, bignum * b) 167 167 { … … 171 171 172 172 173 inline173 static 174 174 int big_set_string(const char * str, int base, bignum * a) 175 175 { -
trunk/src/sh_xfer_client.c
r541 r544 769 769 */ 770 770 sh_passwd (nounce, NULL, NULL, temp); 771 if ( 0 != sl_ strncmp(temp, answer, KEY_LEN))771 if ( 0 != sl_ts_strncmp(temp, answer, KEY_LEN)) 772 772 flag_err = (-1); 773 773 … … 1003 1003 ); 1004 1004 if (M != NULL && 1005 0 == sl_ strncmp (answer, M, KEY_LEN+1))1005 0 == sl_ts_strncmp (answer, M, KEY_LEN+1)) 1006 1006 { 1007 1007 sl_strlcpy (skey->session, … … 1083 1083 pos+1); 1084 1084 flag_err = 1085 sl_ strncmp(&answer[KEY_LEN+pos],1085 sl_ts_strncmp(&answer[KEY_LEN+pos], 1086 1086 sh_util_siggen(skey->session, 1087 1087 buffer, … … 1202 1202 (void) sl_strlcpy(buffer, errmsg, len); 1203 1203 (void) sl_strlcat(buffer, nsrv, len); 1204 flag_err = sl_ strncmp(answer,1205 sh_util_siggen(skey->session,1206 buffer,1207 sl_strlen(buffer),1208 sigbuf, sizeof(sigbuf)),1209 KEY_LEN);1204 flag_err = sl_ts_strncmp(answer, 1205 sh_util_siggen(skey->session, 1206 buffer, 1207 sl_strlen(buffer), 1208 sigbuf, sizeof(sigbuf)), 1209 KEY_LEN); 1210 1210 TPT((0, FIL__, __LINE__, _("msg=<sign %s.>\n"), 1211 1211 sh_util_siggen(skey->session, buffer, -
trunk/src/sh_xfer_server.c
r541 r544 1198 1198 KEY_LEN+1); 1199 1199 1200 if (0 != sl_ strncmp(conn->K, conn->buf, KEY_LEN))1200 if (0 != sl_ts_strncmp(conn->K, conn->buf, KEY_LEN)) 1201 1201 { 1202 1202 TPT((0, FIL__, __LINE__, _("msg=<clt %s>\n"), conn->buf)); … … 1664 1664 */ 1665 1665 buffer = sh_util_strconcat(conn->buf, conn->challenge, NULL); 1666 i = sl_ strncmp(hash,1667 sh_util_siggen(conn->client_entry->session_key,1668 buffer,1669 sl_strlen(buffer),1670 sigbuf, sizeof(sigbuf)),1671 KEY_LEN);1666 i = sl_ts_strncmp(hash, 1667 sh_util_siggen(conn->client_entry->session_key, 1668 buffer, 1669 sl_strlen(buffer), 1670 sigbuf, sizeof(sigbuf)), 1671 KEY_LEN); 1672 1672 TPT((0, FIL__, __LINE__, _("msg=<sign %s.>\n"), 1673 1673 sh_util_siggen(conn->client_entry->session_key, … … 2088 2088 TPT((0, FIL__, __LINE__, _("msg=<c/r: P = %s>\n"), conn->M1)); 2089 2089 2090 if ( 0 != sl_ strncmp(conn->M1, conn->buf, KEY_LEN))2090 if ( 0 != sl_ts_strncmp(conn->M1, conn->buf, KEY_LEN)) 2091 2091 { 2092 2092 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_TCP_BADCONN, … … 2414 2414 */ 2415 2415 if (conn->buf != NULL && 2416 sl_ strncmp(conn->buf, conn->M1, KEY_LEN) == 0)2416 sl_ts_strncmp(conn->buf, conn->M1, KEY_LEN) == 0) 2417 2417 { 2418 2418 /* -
trunk/src/slib.c
r539 r544 588 588 /* 589 589 * Have memset in a different translation unit (i.e. this) to prevent 590 * it to get optimized away 590 * it to get optimized away ...not safe with link-time optimisation... 591 591 */ 592 void *sl_memset(void *s, int c, size_t n) 593 { 594 return memset(s, c,n); 592 void * sl_memset(void *s, int c, size_t n) 593 { 594 /* See: 595 * https://www.usenix.org/sites/default/files/conference/protected-files/usenixsecurity17_slides_zhaomo_yang.pdf 596 */ 597 #if defined(HAVE_EXPLICIT_MEMSET) 598 return explicit_memset(s, c, n); 599 #elif defined(HAVE_EXPLICIT_BZERO) 600 if (c == 0) { 601 explicit_bzero(s, n); 602 return s; 603 } else { 604 return memset(s, c, n); 605 } 606 #elif defined(__GNUC__) 607 memset(s, c, n); 608 __asm__ __volatile__ ("" ::"r"(s): "memory"); /* compiler barrier */ 609 return s; 610 #else 611 if (c == 0) { 612 size_t i; 613 volatile unsigned char * t_s = (volatile unsigned char *)s; 614 for (i=0; i<n; ++i) 615 t_s[i] = 0; 616 return s; 617 } else { 618 return memset(s, c, n); 619 } 620 #endif 595 621 } 596 622 … … 1071 1097 if (a != NULL && b != NULL) 1072 1098 return (strcmp(a, b)); 1099 else if (a == NULL && b != NULL) 1100 return (-1); 1101 else if (a != NULL && b == NULL) 1102 return (1); 1103 else 1104 return (-7); /* default to not equal */ 1105 } 1106 1107 /* Does not report sign. */ 1108 int sl_ts_strncmp(const char * a, const char * b, size_t n) 1109 { 1110 #ifdef SL_FAIL_ON_ERROR 1111 SL_REQUIRE (a != NULL, _("a != NULL")); 1112 SL_REQUIRE (b != NULL, _("b != NULL")); 1113 SL_REQUIRE (n > 0, _("n > 0")); 1114 #endif 1115 1116 if (a != NULL && b != NULL) 1117 { 1118 const unsigned char *a1 = (const unsigned char *)a; 1119 const unsigned char *b1 = (const unsigned char *)b; 1120 size_t i; 1121 int retval=0; 1122 /* The simple index based access is optimized best by the 1123 * compiler (tested with gcc 7.3.0). */ 1124 for (i = 0; i < n; ++i) 1125 { 1126 if (a1[i] == '\0' || b1[i] == '\0') 1127 break; 1128 retval |= (a1[i] ^ b1[i]); 1129 } 1130 /* if (retval == 0) --> false (0) */ 1131 return (retval != 0); 1132 } 1073 1133 else if (a == NULL && b != NULL) 1074 1134 return (-1);
Note:
See TracChangeset
for help on using the changeset viewer.