-*-*-*-*-*-*-*-*- �������� RSA/AES ��������� (�������� ������) -*-*-*-*-*-*-*-*-


����������� ������ RSA4096/AES256, ��� ������ ���� ������


������� (1) � (2) - �������� ��������� ������������
sha(1) � sha(2) - sha �� �������� (��� md5)
tlv() - type length value (������ �������� ��������)

priv = privkey
pub = tlv(1,mod)+tlv(2,exp)


rsa_init(pRSA_EXPORT* e,pRSA_IMPORT i)
rsa_done()

(cpp) rsa_gen_keypair(PBYTE priv, int* len, PBYTE pub, int* len) cntx==-2
(cpp) rsa_set_keypair(priv,len,pub,len) cntx==-2

(cpp) rsa_connect(cntx,pub,len) - ���������� ������������
(cpp) rsa_disconnect(cntx) - ��������� ������������
(cpp) rsa_recv(cntx,msg) - ��� �������� ��������� �������� ����, ���������� 0, ��� �������������� ���������
(cpp) rsa_send(cntx,msg) - ��� ������������ ��������� �������� ����, ���������� ������ ���������� ��� ���

(sim) rsa_inject(cntx,msg) - ��������� ��������� � ������� �� �������� �� �� �������, ���������� �� ��� �� ��
(sim) rsa_check_pub(cntx,sha,sha_len,pub,pub_len) - ������ ��� �������� sha � ���� �� - �� ���� ��������� ���� � ����, ���������� �� ��� �� ��
(sim) rsa_notify(cntx,int) - ����������� � ���������/������� ������������ (event)


RSA_EXPORT rsa;
RSA_IMPORT cb = {
	rsa_inject,
	rsa_check_pub,
	rsa_notify
};


������� (1|2): ������ ���������(0)
if( state ) {
	state=0
	send(���������(0)) - ��������� ������, ���� ���� �������
	"�� ���� ���������� ����������!"
}

������� (1): ���������(1), base64(�������������� ����, sha(1), sha(2)) [2]

������� (2): ������ ���������(1)
1 ��� sha �������?       ���������(2.1), base64(rsa(aes ���� � ������), ������� rsa)        [5]
2 ������� ������ sha(1)? ���������(2.2), base64(��������� ����, rsa-������ ����(2), sha)    [3.2]
3 ������� ������ sha(2)? ���������(2.3), base64(��������� ����, ������ rsa-�������(1), sha) [3.3]
4 �� ������� ������!     ���������(2.4), base64(��������� ����, rsa-������ ����(2), sha)    [3.4]

������� (1): ������ ���������(2)
1 ���������(2.1) - ���������(5), base64(aes("random"),sha) [6]
2 ���������(2.2) - ������ sha(2) ��� ��������. ���������(3.2), base64(rsa(aes ���� � ������), ������� rsa) [5]
3 ���������(2.3) -                             ���������(3.3), base64(rsa-������ ����(1), sha)             [4]
4 ���������(2.4) - ������ sha(2) ��� ��������. ���������(3.4), base64(rsa-������ ����(1), sha)             [4]

������� (2): ������ ���������(3)
1 
2 ���������(3.2) - ���������(5), base64(aes("random"),sha) [6]
3 ���������(3.3) - ������ sha(1) ��� ��������. ���������(4), base64(rsa(aes ���� � ������), ������� rsa) [5]
4 ���������(3.4) - ������ sha(1) ��� ��������. ���������(4), base64(rsa(aes ���� � ������), ������� rsa) [5]

������� (1): ������ ���������(4)
1 ���������(4) - ���������(5), base64(aes("random"),sha) [6]

������� (1|2): ������ ���������(5)
���������(6), base64(aes("random_new"),sha) [7]
"!!!������������ �������!!!"

������� (1|2): ������ ���������(6)
"!!!������������ �������!!!" [7]

������� (1|2): ������ ���������(7) - ������������� ���������

������� (1|2): ������ ���������(F)
if( state ) {
	state=0
	"disconnected by other side"
}


�������0: ������ ������� � ����������� ��� �� ������ ����, ���� �������� ��������� �� � ����� ���� ��� �� �������� ��������,
  �������� ����� ������� � �������� ���������(0)
  ������� ������ ����� �������� ������� ���������, ���� ������� ����� - �� ���� ���������(0) � ��������� ������

�������1: ������������ ������ ���� ������ � ��������� ����� � � ��������� ������ ������� ������ �� ���������
  5-�� �������, ����� ����� ���� �������������� ��������� ���� (���� ��). �������������� � ����� �����
  ���������������� ����������� � ������������� ������ - ��� ������������ ��������� ��������.

�������2: ��� ������������ - ���������(7), aes(zlib(���������))
  zlib - ��� ���������, ����� ������ ����� ������ ����������. ��������� ��� ����������� �� ������������
  (����� ������� � ����, �� ��-����� �� �����).

�������3: ��������� ���� ��������� � �������������� ���������� ����������� (���� ������ ������ ���������
  ������, �� ����� � ���� ���� ��������): ������ ����� � �����.
  �����������: RSA-2048, AES-128/128.


// EOF