symkey: use hmac to fix possible collision attack
This commit is contained in:
		
							parent
							
								
									80aed3c476
								
							
						
					
					
						commit
						07012cb297
					
				| 
						 | 
					@ -184,6 +184,8 @@ bool symkey::encrypt (std::istream&in, std::ostream&out, prng&rng)
 | 
				
			||||||
			hash_proc&hp = **i;
 | 
								hash_proc&hp = **i;
 | 
				
			||||||
			hp.init();
 | 
								hp.init();
 | 
				
			||||||
			hp.eat (& (buf[0]), & (buf[4 + bytes_read]) );
 | 
								hp.eat (& (buf[0]), & (buf[4 + bytes_read]) );
 | 
				
			||||||
 | 
								hp.eat (key);
 | 
				
			||||||
 | 
								hp.eat (otkey);
 | 
				
			||||||
			std::vector<byte> res = hp.finish();
 | 
								std::vector<byte> res = hp.finish();
 | 
				
			||||||
			for (uint j = 0; j < res.size(); ++j, ++hashpos)
 | 
								for (uint j = 0; j < res.size(); ++j, ++hashpos)
 | 
				
			||||||
				buf[hashpos] = res[j];
 | 
									buf[hashpos] = res[j];
 | 
				
			||||||
| 
						 | 
					@ -313,6 +315,8 @@ int symkey::decrypt (std::istream&in, std::ostream&out)
 | 
				
			||||||
			hash_proc&hp = **i;
 | 
								hash_proc&hp = **i;
 | 
				
			||||||
			hp.init();
 | 
								hp.init();
 | 
				
			||||||
			hp.eat (& (buf[0]), & (buf[4 + bytes_read]) );
 | 
								hp.eat (& (buf[0]), & (buf[4 + bytes_read]) );
 | 
				
			||||||
 | 
								hp.eat (key);
 | 
				
			||||||
 | 
								hp.eat (otkey);
 | 
				
			||||||
			std::vector<byte> res = hp.finish();
 | 
								std::vector<byte> res = hp.finish();
 | 
				
			||||||
			for (uint j = 0; j < res.size(); ++j, ++hashpos)
 | 
								for (uint j = 0; j < res.size(); ++j, ++hashpos)
 | 
				
			||||||
				if (buf[hashpos] != res[j]) {
 | 
									if (buf[hashpos] != res[j]) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue