| 
									
										
										
										
											2018-04-24 18:15:56 +02:00
										 |  |  | #include "../include/ed25519.h"
 | 
					
						
							|  |  |  | #include "../include/sha512.h"
 | 
					
						
							|  |  |  | #include "../include/ge.h"
 | 
					
						
							|  |  |  | #include "../include/sc.h"
 | 
					
						
							| 
									
										
										
										
											2013-01-12 00:54:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-04 13:34:01 +01:00
										 |  |  | void ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key) { | 
					
						
							|  |  |  |     sha512_context hash; | 
					
						
							| 
									
										
										
										
											2013-01-12 02:38:34 +01:00
										 |  |  |     unsigned char hram[64]; | 
					
						
							| 
									
										
										
										
											2013-02-04 13:34:01 +01:00
										 |  |  |     unsigned char r[64]; | 
					
						
							| 
									
										
										
										
											2013-01-12 02:38:34 +01:00
										 |  |  |     ge_p3 R; | 
					
						
							| 
									
										
										
										
											2013-01-21 22:50:09 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-07 16:58:14 +02:00
										 |  |  |     _ed_sha512_validate(); | 
					
						
							|  |  |  |     _ed_sha512_functions._ed_sha512_init(&hash); | 
					
						
							|  |  |  |     _ed_sha512_functions._ed_sha512_update(&hash, private_key + 32, 32); | 
					
						
							|  |  |  |     _ed_sha512_functions._ed_sha512_update(&hash, message, message_len); | 
					
						
							|  |  |  |     _ed_sha512_functions._ed_sha512_final(&hash, r); | 
					
						
							| 
									
										
										
										
											2013-01-21 22:50:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-12 02:38:34 +01:00
										 |  |  |     sc_reduce(r); | 
					
						
							|  |  |  |     ge_scalarmult_base(&R, r); | 
					
						
							|  |  |  |     ge_p3_tobytes(signature, &R); | 
					
						
							| 
									
										
										
										
											2013-01-21 22:50:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-07 16:58:14 +02:00
										 |  |  |     _ed_sha512_functions._ed_sha512_init(&hash); | 
					
						
							|  |  |  |     _ed_sha512_functions._ed_sha512_update(&hash, signature, 32); | 
					
						
							|  |  |  |     _ed_sha512_functions._ed_sha512_update(&hash, public_key, 32); | 
					
						
							|  |  |  |     _ed_sha512_functions._ed_sha512_update(&hash, message, message_len); | 
					
						
							|  |  |  |     _ed_sha512_functions._ed_sha512_final(&hash, hram); | 
					
						
							| 
									
										
										
										
											2013-01-21 22:50:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-12 02:38:34 +01:00
										 |  |  |     sc_reduce(hram); | 
					
						
							| 
									
										
										
										
											2013-02-04 13:34:01 +01:00
										 |  |  |     sc_muladd(signature + 32, hram, private_key, r); | 
					
						
							| 
									
										
										
										
											2013-01-12 00:54:40 +01:00
										 |  |  | } |