static inline unsigned int constant_time_ge(unsigned int a, unsigned int b)
	{
	unsigned int ge;
	ge = ~((a ^ b) | (a - b));
	ge |= a & ~b;
	return constant_time_msb(ge);
	}
['static int\ndtls1_process_buffered_records(SSL *s)\n    {\n    pitem *item;\n    item = pqueue_peek(s->d1->unprocessed_rcds.q);\n    if (item)\n        {\n        if (s->d1->unprocessed_rcds.epoch != s->d1->r_epoch)\n            return(1);\n        while (pqueue_peek(s->d1->unprocessed_rcds.q))\n            {\n            dtls1_get_unprocessed_record(s);\n            if ( ! dtls1_process_record(s))\n                return(0);\n            dtls1_buffer_record(s, &(s->d1->processed_rcds),\n                s->s3->rrec.seq_num);\n            }\n        }\n    s->d1->processed_rcds.epoch = s->d1->r_epoch;\n    s->d1->unprocessed_rcds.epoch = s->d1->r_epoch + 1;\n    return(1);\n    }', 'static int\ndtls1_process_record(SSL *s)\n{\n\tint i,al;\n\tint enc_err;\n\tSSL_SESSION *sess;\n\tSSL3_RECORD *rr;\n\tunsigned int mac_size;\n\tunsigned char md[EVP_MAX_MD_SIZE];\n\trr= &(s->s3->rrec);\n\tsess = s->session;\n\trr->input= &(s->packet[DTLS1_RT_HEADER_LENGTH]);\n\tif (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH)\n\t\t{\n\t\tal=SSL_AD_RECORD_OVERFLOW;\n\t\tSSLerr(SSL_F_DTLS1_PROCESS_RECORD,SSL_R_ENCRYPTED_LENGTH_TOO_LONG);\n\t\tgoto f_err;\n\t\t}\n\trr->data=rr->input;\n\trr->orig_len=rr->length;\n\tenc_err = s->method->ssl3_enc->enc(s,0);\n\tif (enc_err == 0)\n\t\t{\n\t\trr->length = 0;\n\t\ts->packet_length = 0;\n\t\tgoto err;\n\t\t}\n#ifdef TLS_DEBUG\nprintf("dec %d\\n",rr->length);\n{ unsigned int z; for (z=0; z<rr->length; z++) printf("%02X%c",rr->data[z],((z+1)%16)?\' \':\'\\n\'); }\nprintf("\\n");\n#endif\n\tif ((sess != NULL) &&\n\t    (s->enc_read_ctx != NULL) &&\n\t    (EVP_MD_CTX_md(s->read_hash) != NULL))\n\t\t{\n\t\tunsigned char *mac = NULL;\n\t\tunsigned char mac_tmp[EVP_MAX_MD_SIZE];\n\t\tmac_size=EVP_MD_CTX_size(s->read_hash);\n\t\tOPENSSL_assert(mac_size <= EVP_MAX_MD_SIZE);\n\t\tif (rr->orig_len < mac_size ||\n\t\t    (EVP_CIPHER_CTX_mode(s->enc_read_ctx) == EVP_CIPH_CBC_MODE &&\n\t\t     rr->orig_len < mac_size+1))\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_DTLS1_PROCESS_RECORD,SSL_R_LENGTH_TOO_SHORT);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (EVP_CIPHER_CTX_mode(s->enc_read_ctx) == EVP_CIPH_CBC_MODE)\n\t\t\t{\n\t\t\tmac = mac_tmp;\n\t\t\tssl3_cbc_copy_mac(mac_tmp, rr, mac_size);\n\t\t\trr->length -= mac_size;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\trr->length -= mac_size;\n\t\t\tmac = &rr->data[rr->length];\n\t\t\t}\n\t\ti=s->method->ssl3_enc->mac(s,md,0  );\n\t\tif (i < 0 || mac == NULL || CRYPTO_memcmp(md, mac, (size_t)mac_size) != 0)\n\t\t\tenc_err = -1;\n\t\tif (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH+mac_size)\n\t\t\tenc_err = -1;\n\t\t}\n\tif (enc_err < 0)\n\t\t{\n\t\trr->length = 0;\n\t\ts->packet_length = 0;\n\t\tgoto err;\n\t\t}\n\tif (s->expand != NULL)\n\t\t{\n\t\tif (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH)\n\t\t\t{\n\t\t\tal=SSL_AD_RECORD_OVERFLOW;\n\t\t\tSSLerr(SSL_F_DTLS1_PROCESS_RECORD,SSL_R_COMPRESSED_LENGTH_TOO_LONG);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (!ssl3_do_uncompress(s))\n\t\t\t{\n\t\t\tal=SSL_AD_DECOMPRESSION_FAILURE;\n\t\t\tSSLerr(SSL_F_DTLS1_PROCESS_RECORD,SSL_R_BAD_DECOMPRESSION);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t}\n\tif (rr->length > SSL3_RT_MAX_PLAIN_LENGTH)\n\t\t{\n\t\tal=SSL_AD_RECORD_OVERFLOW;\n\t\tSSLerr(SSL_F_DTLS1_PROCESS_RECORD,SSL_R_DATA_LENGTH_TOO_LONG);\n\t\tgoto f_err;\n\t\t}\n\trr->off=0;\n\ts->packet_length=0;\n\tdtls1_record_bitmap_update(s, &(s->d1->bitmap));\n\treturn(1);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n\treturn(0);\n}', 'void ssl3_cbc_copy_mac(unsigned char* out,\n\t\t       const SSL3_RECORD *rec,\n\t\t       unsigned md_size)\n\t{\n#if defined(CBC_MAC_ROTATE_IN_PLACE)\n\tunsigned char rotated_mac_buf[64+EVP_MAX_MD_SIZE];\n\tunsigned char *rotated_mac;\n#else\n\tunsigned char rotated_mac[EVP_MAX_MD_SIZE];\n#endif\n\tunsigned mac_end = rec->length;\n\tunsigned mac_start = mac_end - md_size;\n\tunsigned scan_start = 0;\n\tunsigned i, j;\n\tunsigned div_spoiler;\n\tunsigned rotate_offset;\n\tOPENSSL_assert(rec->orig_len >= md_size);\n\tOPENSSL_assert(md_size <= EVP_MAX_MD_SIZE);\n#if defined(CBC_MAC_ROTATE_IN_PLACE)\n\trotated_mac = rotated_mac_buf + ((0-(size_t)rotated_mac_buf)&63);\n#endif\n\tif (rec->orig_len > md_size + 255 + 1)\n\t\tscan_start = rec->orig_len - (md_size + 255 + 1);\n\tdiv_spoiler = md_size >> 1;\n\tdiv_spoiler <<= (sizeof(div_spoiler)-1)*8;\n\trotate_offset = (div_spoiler + mac_start - scan_start) % md_size;\n\tmemset(rotated_mac, 0, md_size);\n\tfor (i = scan_start, j = 0; i < rec->orig_len; i++)\n\t\t{\n\t\tunsigned char mac_started = constant_time_ge_8(i, mac_start);\n\t\tunsigned char mac_ended = constant_time_ge_8(i, mac_end);\n\t\tunsigned char b = rec->data[i];\n\t\trotated_mac[j++] |= b & mac_started & ~mac_ended;\n\t\tj &= constant_time_lt(j,md_size);\n\t\t}\n#if defined(CBC_MAC_ROTATE_IN_PLACE)\n\tj = 0;\n\tfor (i = 0; i < md_size; i++)\n\t\t{\n\t\t((volatile unsigned char *)rotated_mac)[rotate_offset^32];\n\t\tout[j++] = rotated_mac[rotate_offset++];\n\t\trotate_offset &= constant_time_lt(rotate_offset,md_size);\n\t\t}\n#else\n\tmemset(out, 0, md_size);\n\trotate_offset = md_size - rotate_offset;\n\trotate_offset &= constant_time_lt(rotate_offset,md_size);\n\tfor (i = 0; i < md_size; i++)\n\t\t{\n\t\tfor (j = 0; j < md_size; j++)\n\t\t\tout[j] |= rotated_mac[i] & constant_time_eq_8(j, rotate_offset);\n\t\trotate_offset++;\n\t\trotate_offset &= constant_time_lt(rotate_offset,md_size);\n\t\t}\n#endif\n\t}', 'static inline unsigned char constant_time_ge_8(unsigned int a, unsigned int b)\n\t{\n\treturn (unsigned char)(constant_time_ge(a, b));\n\t}', 'static inline unsigned int constant_time_ge(unsigned int a, unsigned int b)\n\t{\n\tunsigned int ge;\n\tge = ~((a ^ b) | (a - b));\n\tge |= a & ~b;\n\treturn constant_time_msb(ge);\n\t}']