1*c459080aSangelos# $OpenBSD: HOWTO.add.crypto,v 1.3 2000/01/25 09:08:09 angelos Exp $ 2983e9580Sangelos 3983e9580SangelosThis document describes how to add support for digital signature algorithms, 4983e9580Sangeloshash functions, and ASCII encoding mechanisms in this implementation. 5983e9580Sangelos 6983e9580SangelosFor a signature algorithm: 7983e9580Sangelos 8983e9580Sangelos- Add the appropriate include files in keynote.h 9983e9580Sangelos- Create one or more strings describing the signature algorithm 10983e9580Sangelos prefixes, and add those to keynote.h (the SIG_* definitions). 11983e9580Sangelos- Add a definition for the algorithm in keynote.h (the 12983e9580Sangelos KEYNOTE_ALGORITHM_* definitions). 13983e9580Sangelos- Define the algorithm public key prefixes, and add them to 14983e9580Sangelos signature.h (the *_HEX, *_HEX_LEN, *_BASE64, *_BASE64_LEN 15983e9580Sangelos definitions). 16*c459080aSangelos- In auxil.c, function keynote_keyhash(), add to the switch statement 17983e9580Sangelos a case handling the new algorithm; the return value is an integer, 18983e9580Sangelos and is used as an index into a hash table. 19983e9580Sangelos- In signature.c: 20983e9580Sangelos - In keynote_free_key(), add code to free any memory allocated for 21983e9580Sangelos storing a key for the new algorithm. 22983e9580Sangelos - In keynote_get_sig_algorithm(), add code that checks whether a 23983e9580Sangelos signature string begins with one of the prefixes for the new 24983e9580Sangelos algorithm that were defined in keynote.h 25983e9580Sangelos - Similarly, in keynote_get_key_algorithm() for key strings, using 26983e9580Sangelos the key prefixes defined in signature.h 27983e9580Sangelos - In kn_decode_key(), add code that converts a bit string to 28983e9580Sangelos the new algorithm's structure for storing a key (use the DSA 29983e9580Sangelos code as a guide). 30983e9580Sangelos - Similarly for kn_encode_key() 312350ed37Sangelos - In kn_keycompare(), add code that compares two keys and 32983e9580Sangelos returns RETURN_TRUE if they are equal, and RETURN_FALSE otherwise. 33983e9580Sangelos - In keynote_signverify_assertion, add code that verifies a 34983e9580Sangelos signature for the new algorithm. 35983e9580Sangelos - Likewise for signature generation in keynote_sign_assertion() 36983e9580Sangelos- In keynote-keygen.c, replicate the code for DSA key generation to 37983e9580Sangelos support the new algorithm. 38983e9580Sangelos 39983e9580SangelosFor a hash algorithm: 40983e9580Sangelos 41983e9580Sangelos- Add the necessary include files in keynote.h 42983e9580Sangelos- Add a KEYNOTE_HASH_* definition for the algorithm in signature.h 43983e9580Sangelos- In signature.h, if the length of the new hash function's result is 44983e9580Sangelos more than LARGEST_HASH_SIZE (currently 20 bytes, for SHA1), then 45983e9580Sangelos replace that value with the new function's hash result length. 46983e9580Sangelos- In signature.c: 47983e9580Sangelos - In keynote_sigverify_assertion(), add code in the switch statement 48983e9580Sangelos for generating a hash of the assertion and the signature algorithm 49983e9580Sangelos name (use the SHA1 code as an example). 50983e9580Sangelos - Likewise in keynote_sign_assertion() 51983e9580Sangelos 52983e9580SangelosFor an ASCII-encoding algorithm: 53983e9580Sangelos 54983e9580Sangelos- Add the necessary include files in keynote.h 55983e9580Sangelos- Add additional SIG_* definitions in keynote.h 56983e9580Sangelos- Add an ENCODING_* definition in keynote.h 57983e9580Sangelos- Add additional key prefix string definitions in signature.h 58983e9580Sangelos- In signature.c: 59983e9580Sangelos - In keynote_get_sig_algorithm(), add code for detecting signatures 60983e9580Sangelos with this encoding. 61983e9580Sangelos - Likewise for keys in keynote_get_key_algorithm() 62983e9580Sangelos - In kn_decode_key(), add code in the switch statement for decoding 63983e9580Sangelos ASCII-encoded keys. 64983e9580Sangelos - Likewise in kn_encode_key() for encoding keys. 65983e9580Sangelos - Likewise in keynote_sigverify_assertion() for decoding signatures. 66983e9580Sangelos - Add the necessary checks in keynote_sign_assertion() for handling 67983e9580Sangelos the new encoding, and code in the switch statement for doing the 68983e9580Sangelos encoding of the signature. 69983e9580Sangelos- Add the necessary checks in keynote-keygen.c for handling the 70983e9580Sangelos new algorithm. 71983e9580Sangelos 72