diff --git a/Control/keystore.c b/Control/keystore.c
index c7c55b02101148c1c89b732ba1c15f81cbe42bf6..d0689792e3e4df895831a020f817c2527508d866 100644
--- a/Control/keystore.c
+++ b/Control/keystore.c
@@ -215,34 +215,15 @@ uint8_t keystore_init_slot(uint16_t index, KEY keyout){
 	if (!keystore_write_slot_status(index, KEYSLOT_USED)) return 0;
 	_delay_us(40);
 	
-	HASH fullhash;
-	sha1(&fullhash, keyout, (sizeof(KEY) + sizeof(SALT))*8);
-	memcpy(&hashes[index], fullhash, sizeof(HASH_HEAD));
+	sha1_ctx_t s;
+	sha1_init(&s);
+	sha1_nextBlock(&s, keyout);
+	sha1_lastBlock(&s, salt, sizeof(SALT));
+	sha1_ctx2hashhead(&hashes[index], &s);
 	
 	return 1;
 }
 
-/**
- * Initializes the given keyslot with an empty (all 0-bytes)
- * @param index index to the keyslot to initialize
- * @return 1 if successful, 0 if not.
- */
-uint8_t keystore_init_slot_empty(uint16_t index, KEY keyout){
-	KEY key;
-	memset(key, 0, sizeof(KEY));
-	if (!keystore_write_slot_status(index, KEYSLOT_EMPTY)) return 0;
-	_delay_us(40);
-	if (!keystore_write_key(index, key)) return 0;
-	_delay_us(40);
-	if (!keystore_write_slot_status(index, KEYSLOT_USED)) return 0;
-	_delay_us(40);
-	
-	HASH fullhash;
-	sha1(&fullhash, keyout, (sizeof(KEY) + sizeof(SALT))*8);
-	memcpy(&hashes[index], fullhash, sizeof(HASH_HEAD));
-	
-	return 1;
-}
 
 uint8_t keystore_clear_slot(uint16_t index){
 	if (!keystore_write_slot_status(index, KEYSLOT_EMPTY)) return 0;
diff --git a/common/sha1/sha1.c b/common/sha1/sha1.c
index 1b052dcd27e0980e07676feb4feba0e6ce4419ac..ac04bfb97f6f6a6a107ec6e605a820b3f3c226f8 100644
--- a/common/sha1/sha1.c
+++ b/common/sha1/sha1.c
@@ -231,6 +231,19 @@ void sha1_ctx2hash (sha1_hash_t *dest, sha1_ctx_t *state){
 
 /********************************************************************************************************/
 
+void sha1_ctx2hashhead (uint8_t dest[4], sha1_ctx_t *state){
+#if defined LITTLE_ENDIAN
+	((uint32_t*)dest)[0] = change_endian32(state->h[0]);
+#elif BIG_ENDIAN
+	if (dest != state->h)
+		memcpy(dest, state->h, 4);
+#else
+# error unsupported endian type!
+#endif
+}
+
+/********************************************************************************************************/
+
 uint8_t sha1_ctx_hash_compare(sha1_hash_t *ref, sha1_ctx_t *state){
 #if defined LITTLE_ENDIAN
 	uint8_t i;
diff --git a/common/sha1/sha1.h b/common/sha1/sha1.h
index ba779771bf09e5d6c0067d7078ac6eaf706c6a38..29d1a77ca2d1fa6a1bf022cac9b18cab75621c40 100644
--- a/common/sha1/sha1.h
+++ b/common/sha1/sha1.h
@@ -102,6 +102,15 @@ void sha1_lastBlock (sha1_ctx_t *state, const void* block, uint16_t length_b);
  */ 
 void sha1_ctx2hash (sha1_hash_t *dest, sha1_ctx_t *state);
 
+/** \fn sha1_ctx2hashhead(uint8_t dest[4], sha1_ctx_t *state)
+ * \brief convert a state variable into a 4 byte hash value head
+ * Writes the hash value head corresponding to the state to the memory pointed by dest.
+ * \param dest pointer to the hash value destination
+ * \param state pointer to the hash context
+ */ 
+void sha1_ctx2hashhead (uint8_t dest[4], sha1_ctx_t *state);
+
+
 /** \fn sha1_ctx_hash_compare(sha1_hash_t *ref, sha1_ctx_t *state)
  * \brief compares a state variable with an actual hash value
  * \param ref sha1 hash to compere with