reorganised crypto functions