mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-26 07:22:06 +00:00 
			
		
		
		
	 5963f6f9ff
			
		
	
	
		5963f6f9ff
		
	
	
	
	
		
			
			Since the operations are already complicated and will become even more so soon, let's split them into their own files. We can also integrate the NumberTheory operations that would better fit there into this class as well. This commit doesn't change behaviors, but moves the allocation of some variables into caller classes.
		
			
				
	
	
		
			43 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2020, Ali Mohammad Pur <mpfard@serenityos.org>
 | |
|  * Copyright (c) 2020-2021, Dex♪ <dexes.ttp@gmail.com>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include "UnsignedBigIntegerAlgorithms.h"
 | |
| 
 | |
| namespace Crypto {
 | |
| 
 | |
| void UnsignedBigIntegerAlgorithms::destructive_GCD_without_allocation(
 | |
|     UnsignedBigInteger& temp_a,
 | |
|     UnsignedBigInteger& temp_b,
 | |
|     UnsignedBigInteger& temp_1,
 | |
|     UnsignedBigInteger& temp_2,
 | |
|     UnsignedBigInteger& temp_3,
 | |
|     UnsignedBigInteger& temp_4,
 | |
|     UnsignedBigInteger& temp_quotient,
 | |
|     UnsignedBigInteger& temp_remainder,
 | |
|     UnsignedBigInteger& output)
 | |
| {
 | |
|     for (;;) {
 | |
|         if (temp_a == 0) {
 | |
|             output.set_to(temp_b);
 | |
|             return;
 | |
|         }
 | |
| 
 | |
|         // temp_b %= temp_a
 | |
|         divide_without_allocation(temp_b, temp_a, temp_1, temp_2, temp_3, temp_4, temp_quotient, temp_remainder);
 | |
|         temp_b.set_to(temp_remainder);
 | |
|         if (temp_b == 0) {
 | |
|             output.set_to(temp_a);
 | |
|             return;
 | |
|         }
 | |
| 
 | |
|         // temp_a %= temp_b
 | |
|         divide_without_allocation(temp_a, temp_b, temp_1, temp_2, temp_3, temp_4, temp_quotient, temp_remainder);
 | |
|         temp_a.set_to(temp_remainder);
 | |
|     }
 | |
| }
 | |
| 
 | |
| }
 |