cederom commented on code in PR #18396:
URL: https://github.com/apache/nuttx/pull/18396#discussion_r2809899315


##########
tools/mkpasswd.py:
##########
@@ -0,0 +1,204 @@
+#!/usr/bin/env python3
+############################################################################
+# tools/mkpasswd.py
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################
+
+"""Generate a NuttX /etc/passwd entry with a TEA-encrypted password hash.
+
+This script implements the same Tiny Encryption Algorithm (TEA) and base64
+encoding used by NuttX at runtime (libs/libc/misc/lib_tea_encrypt.c and
+apps/fsutils/passwd) to produce a passwd line suitable for embedding in a
+ROMFS image at build time.
+
+Usage:
+    python3 mkpasswd.py --user admin --password secret
+    python3 mkpasswd.py --user admin --password secret -o /path/to/passwd
+"""
+
+import argparse
+import os
+import struct
+import sys
+
+# The TEA key schedule constant (0x9e3779b9 is the golden ratio derived value)
+TEA_KEY_SCHEDULE_CONSTANT = 0x9E3779B9
+MASK32 = 0xFFFFFFFF
+
+
+def tea_encrypt(v0, v1, key):
+    """Encrypt two 32-bit values using TEA with the given 128-bit key.
+
+    This matches the C implementation in libs/libc/misc/lib_tea_encrypt.c.
+    """
+    sum_val = 0
+    for _ in range(32):
+        sum_val = (sum_val + TEA_KEY_SCHEDULE_CONSTANT) & MASK32
+        v0 = (v0 + ((((v1 << 4) & MASK32) + key[0]) ^ ((v1 + sum_val) & 
MASK32) ^ (((v1 >> 5) & MASK32) + key[1]))) & MASK32
+        v1 = (v1 + ((((v0 << 4) & MASK32) + key[2]) ^ ((v0 + sum_val) & 
MASK32) ^ (((v0 >> 5) & MASK32) + key[3]))) & MASK32
+    return v0, v1
+
+
+def passwd_base64(binary):
+    """Encode a 6-bit value as a base64 character.
+
+    This matches the custom base64 encoding in 
apps/fsutils/passwd/passwd_encrypt.c.

Review Comment:
   hmm why there was custom b64 encoding? if for obscurity then we just 
revealed it :D 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to