@@ -31,7 +31,7 @@ u32int rfccount = 1;
3131char rfctext [] = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, "
3232 "sunscreen would be it." ;
3333uchar rfcout [3 * ChachaBsize ];
34- uchar rfcref [3 * ChachaBsize ] = {
34+ uchar rfcref [] = {
3535 0x6e , 0x2e , 0x35 , 0x9a , 0x25 , 0x68 , 0xf9 , 0x80 , 0x41 , 0xba , 0x07 , 0x28 , 0xdd , 0x0d , 0x69 , 0x81 ,
3636 0xe9 , 0x7e , 0x7a , 0xec , 0x1d , 0x43 , 0x60 , 0xc2 , 0x0a , 0x27 , 0xaf , 0xcc , 0xfd , 0x9f , 0xae , 0x0b ,
3737 0xf9 , 0x1b , 0x65 , 0xc5 , 0x52 , 0x47 , 0x33 , 0xab , 0x8f , 0x59 , 0x3d , 0xab , 0xcd , 0x62 , 0xb3 , 0x57 ,
@@ -42,10 +42,26 @@ uchar rfcref[3*ChachaBsize] = {
4242 0x87 , 0x4d
4343};
4444
45+ uchar ccpaad [] = {
46+ 0x50 , 0x51 , 0x52 , 0x53 , 0xc0 , 0xc1 , 0xc2 , 0xc3 , 0xc4 , 0xc5 , 0xc6 , 0xc7 ,
47+ };
48+ uchar ccpkey [] = {
49+ 0x80 , 0x81 , 0x82 , 0x83 , 0x84 , 0x85 , 0x86 , 0x87 , 0x88 , 0x89 , 0x8a , 0x8b , 0x8c , 0x8d , 0x8e , 0x8f ,
50+ 0x90 , 0x91 , 0x92 , 0x93 , 0x94 , 0x95 , 0x96 , 0x97 , 0x98 , 0x99 , 0x9a , 0x9b , 0x9c , 0x9d , 0x9e , 0x9f ,
51+ };
52+ uchar ccpiv [] = {
53+ 0x07 , 0x00 , 0x00 , 0x00 ,
54+ 0x40 , 0x41 , 0x42 , 0x43 , 0x44 , 0x45 , 0x46 , 0x47 ,
55+ };
56+ uchar ccptag [] = {
57+ 0x1a , 0xe1 , 0x0b , 0x59 , 0x4f , 0x09 , 0xe2 , 0x6a , 0x7e , 0x90 , 0x2e , 0xcb , 0xd0 , 0x60 , 0x06 , 0x91 ,
58+ };
59+
4560void
4661main (int argc , char * * argv )
4762{
4863 Chachastate s ;
64+ uchar tag [16 ];
4965 int n ;
5066
5167 ARGBEGIN {
@@ -54,17 +70,51 @@ main(int argc, char **argv)
5470 print ("key:\n" );
5571 printblock (rfckey , sizeof (rfckey ));
5672 n = strlen (rfctext );
57- setupChachastate (& s , rfckey , sizeof (rfckey ), rfcnonce , 0 );
73+ setupChachastate (& s , rfckey , sizeof (rfckey ), rfcnonce , sizeof ( rfcnonce ), 0 );
5874 chacha_setblock (& s , rfccount );
5975 print ("rfc in:\n" );
6076 printblock ((uchar * )rfctext , n );
6177 chacha_encrypt2 ((uchar * )rfctext , rfcout , n , & s );
6278 print ("rfc out:\n" );
6379 printblock (rfcout , n );
64- if (memcmp (rfcout , rfcref , sizeof (rfcout )) != 0 ){
80+ if (memcmp (rfcout , rfcref , sizeof (rfcref )) != 0 ){
6581 print ("failure of vision\n" );
6682 exits ("wrong" );
6783 }
84+ print ("\n" );
85+
86+ print ("ccpoly key:\n" );
87+ printblock (ccpkey , sizeof (ccpkey ));
88+
89+ print ("ccpoly iv:\n" );
90+ printblock (ccpiv , sizeof (ccpiv ));
91+
92+ setupChachastate (& s , ccpkey , sizeof (ccpkey ), ccpiv , sizeof (ccpiv ), 20 );
93+
94+ memmove (rfcout , rfctext , sizeof (rfctext )- 1 );
95+ ccpoly_encrypt (rfcout , sizeof (rfctext )- 1 , ccpaad , sizeof (ccpaad ), tag , & s );
96+
97+ print ("ccpoly cipher:\n" );
98+ printblock (rfcout , sizeof (rfctext )- 1 );
99+
100+ print ("ccpoly tag:\n" );
101+ printblock (tag , sizeof (tag ));
102+
103+ if (memcmp (tag , ccptag , sizeof (tag )) != 0 ){
104+ print ("bad ccpoly tag\n" );
105+ exits ("wrong" );
106+ }
107+
108+ if (ccpoly_decrypt (rfcout , sizeof (rfctext )- 1 , ccpaad , sizeof (ccpaad ), tag , & s ) != 0 ){
109+ print ("ccpoly decryption failed\n" );
110+ exits ("wrong" );
111+ }
112+
113+ if (memcmp (rfcout , rfctext , sizeof (rfctext )- 1 ) != 0 ){
114+ print ("ccpoly bad decryption\n" );
115+ exits ("wrong" );
116+ }
117+
68118 print ("passed\n" );
69119 exits (nil );
70120}
0 commit comments