docs: def gen_keys(hsm, args):
      """
      The main key generating loop.
      """
  
      if args.verbose:
          print "Generating %i keys :\n" % (args.count)
      else:
          print "Generating %i keys" % (args.count)
  
      for int_id in range(args.start_id, args.start_id + args.count):
          public_id = ("%x" % int_id).rjust(args.public_id_chars, '0')
          padded_id = pyhsm.yubikey.modhex_encode(public_id)
  
          if args.verbose:
              print "  %s" % (padded_id)
  
          num_bytes = len(pyhsm.aead_cmd.YHSM_YubiKeySecret('a' * 16, 'b' * 6).pack())
          hsm.load_random(num_bytes)
          for kh in args.key_handles.keys():
              if args.random_nonce:
                  nonce = ""
              else:
                  nonce = public_id.decode('hex')
              aead = hsm.generate_aead(nonce, kh)
  
              filename = output_filename(args.output_dir, args.key_handles[kh], padded_id)
  
              if args.verbose:
                  print "    %4s, %i bytes (%s) -> %s" % \
                      (args.key_handles[kh], len(aead.data), shorten_aead(aead), filename)
              aead.save(filename)
  
          if args.verbose:
              print ""
  
      print "\nDone\n"