Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <cstdlib>
- #include <stdio.h>
- typedef unsigned char u8;
- typedef unsigned short u16;
- void escape(void *p) {
- asm volatile("" : : "g"(p) : "memory");
- }
- void clobber() {
- asm volatile("" : : : "memory");
- }
- class additive_hasher{
- public:
- /* returns rounded up to capacity size */
- static size_t hash(const u8 *keyc, size_t len, size_t capacity){
- const u16 *key2;
- // const u8 *keyc = (const u8 *)key;
- size_t hash = len, i;
- if((len % 2)){
- key2 = (const u16 *)(keyc + 1);
- len--;
- hash += keyc[0];
- }else{
- key2 = (const u16 *)(keyc);
- }
- len /= 2;
- for(i=0; i<len; ++i)
- hash += key2[i];
- return (hash & (capacity - 1));
- }
- };
- int main(){
- srand(time(NULL));
- size_t len;
- scanf("%lu", &len);
- u8 x[len];
- for(size_t i = 0; i < len; i++)
- x[i] = rand();
- escape(x);
- clobber();
- printf("out %lu\n", additive_hasher::hash(x, len, 100));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement