- static u_int16_t *h = (u_int16_t *) NULL;
- static u_int16_t n = HASH_MINSIZE / HASH_ENTRYSIZE;
- register u_int32_t i, j;
- u_int32_t l;
- register unsigned char *c;
- unsigned char *d;
-
- if (len > (SSH_MAXBLOCKS * SSH_BLOCKSIZE) ||
- len % SSH_BLOCKSIZE != 0) {
- fatal("detect_attack: bad length %d", len);
- }
-
- for (l = n; l < HASH_FACTOR(len / SSH_BLOCKSIZE); l = l << 2);
-
- if (h == NULL)
- {
- debug("Installing crc compensation attack detector.");
- n = l;
- h = (u_int16_t *) xmalloc(n * HASH_ENTRYSIZE);
- } else
- {
- if (l > n)
- {
- n = l;
- h = (u_int16_t *) xrealloc(h, n * HASH_ENTRYSIZE);
- }
- }
-
-
- if (len <= HASH_MINBLOCKS)
- {
- for (c = buf; c < buf + len; c += SSH_BLOCKSIZE)
- {
- if (IV && (!CMP(c, IV)))
- {
- if ((check_crc(c, buf, len, IV)))
- return (DEATTACK_DETECTED);
- else
- break;
- }
- for (d = buf; d < c; d += SSH_BLOCKSIZE)
- {
- if (!CMP(c, d))
- {
- if ((check_crc(c, buf, len, IV)))
- return (DEATTACK_DETECTED);
- else
- break;
+ static u_int16_t *h = (u_int16_t *) NULL;
+ static u_int32_t n = HASH_MINSIZE / HASH_ENTRYSIZE;
+ u_int32_t i, j;
+ u_int32_t l;
+ u_char *c;
+ u_char *d;
+
+ if (len > (SSH_MAXBLOCKS * SSH_BLOCKSIZE) ||
+ len % SSH_BLOCKSIZE != 0) {
+ fatal("detect_attack: bad length %d", len);
+ }
+ for (l = n; l < HASH_FACTOR(len / SSH_BLOCKSIZE); l = l << 2)
+ ;
+
+ if (h == NULL) {
+ debug("Installing crc compensation attack detector.");
+ h = (u_int16_t *) xmalloc(l * HASH_ENTRYSIZE);
+ n = l;
+ } else {
+ if (l > n) {
+ h = (u_int16_t *) xrealloc(h, l * HASH_ENTRYSIZE);
+ n = l;
+ }
+ }
+
+ if (len <= HASH_MINBLOCKS) {
+ for (c = buf; c < buf + len; c += SSH_BLOCKSIZE) {
+ if (IV && (!CMP(c, IV))) {
+ if ((check_crc(c, buf, len, IV)))
+ return (DEATTACK_DETECTED);
+ else
+ break;
+ }
+ for (d = buf; d < c; d += SSH_BLOCKSIZE) {
+ if (!CMP(c, d)) {
+ if ((check_crc(c, buf, len, IV)))
+ return (DEATTACK_DETECTED);
+ else
+ break;
+ }
+ }
+ }
+ return (DEATTACK_OK);